Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilities ii #3018

Merged
merged 6 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Types of change:
### Changed
- [Html - Link Relative Paths - Change part of PQ as it wasn't worder properly](https://github.com/enkidevs/curriculum/pull/2985)
- [Python - Format Text Paragraphs With Textwrap - Make the fill method more clear](https://github.com/enkidevs/curriculum/pull/2981)
- [Python - Utilities II - Move single-line commands to a single line, update indentation in codeblocks from 4 to 2 spaces](https://github.com/enkidevs/curriculum/pull/3018)
- [Python - Working With Strings - Move single-line commands to a single line, update indentation in codeblocks from 4 to 2 spaces](https://github.com/enkidevs/curriculum/pull/3019)
- [Python - Arrays I - Move single-line commands to a single line, update indentation in codeblocks from 4 to 2 spaces](https://github.com/enkidevs/curriculum/pull/3020)
- [Python - Arrays II - Move single-line commands to a single line, update indentation in codeblocks from 4 to 2 spaces](https://github.com/enkidevs/curriculum/pull/3021)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Convert `my_generator` to a coroutine function:
import types

def my_generator():
yield 1
yield 1

my_coroutine = ???.???(my_generator)
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ revisionQuestion:

## Content

`difflib`'s `SequenceMatcher` class and its ratio method makes it easy to compute the "similarity" of two sequences.
`difflib`'s `SequenceMatcher` class and its ratio method make it easy to compute the "similarity" of two sequences.

```python
import difflib
Expand All @@ -42,7 +42,7 @@ With the output:
40.0
```

*Junk* sequences (such as whitespace or blank lines) can be passed as the first argument of the function, for them not to be taken into account. The default value is `None`, when nothing is ignored.
*Junk* sequences (such as whitespace or blank lines) can be passed as the first argument of the function, for them not to be taken into account. The default value is `None` when nothing is ignored.

It can be used to compare sequences of characters as well, i.e. strings.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ revisionQuestion:

## Content

Python's `struct` module has routines for converting between binary and text data, in both directions.
Python's `struct` module has routines for converting between binary and text data in both directions.

Import the module:

Expand Down
9 changes: 3 additions & 6 deletions python/python-core/utilities-ii/working-with-junk-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ For the sake of the argument we will work with this class' function called `find
```python
from difflib import SequenceMatcher

s = SequenceMatcher(None, \
" abcd", "abcd abcd")
s = SequenceMatcher(None, " abcd", "abcd abcd")
print(s.find_longest_match(0, 5, 0, 9))

# prints Match(a=0, b=4, size=5)
Expand All @@ -51,8 +50,7 @@ See how in the first scenario we searched for the longest match between the two
But if we treat white spaces as **Junk** the output will be different:

```python
s = SequenceMatcher(lambda x: x == " ",
" abcd", "abcd abcd")
s = SequenceMatcher(lambda x: x == " ", " abcd", "abcd abcd")
print(s.find_longest_match(0, 5, 0, 9))
# prints Match(a=1, b=0, size=4)
```
Expand All @@ -65,8 +63,7 @@ print(s.find_longest_match(0, 5, 0, 9))
Complete the `SequenceMatcher` constructor such that empty spaces are treated as junk:

```python
s = SequenceMatcher(??? x: x == ???,
“ abcd”, “abcd abcd”)
s = SequenceMatcher(??? x: x == ???, “ abcd”, “abcd abcd”)
```

- `lambda`
Expand Down