Browse Source

Double quotes around strings to single

pull/3/head
Jure Šorn 6 years ago
parent
commit
3cf8659c5b
1 changed files with 15 additions and 14 deletions
  1. 29
      README.md

29
README.md

@ -579,11 +579,11 @@ Exceptions
```python ```python
while True: while True:
try: try:
x = int(input("Please enter a number: "))
x = int(input('Please enter a number: '))
except ValueError: except ValueError:
print("Oops! That was no valid number. Try again...")
print('Oops! That was no valid number. Try again...')
else: else:
print("Thank you.")
print('Thank you.')
break break
``` ```
@ -623,13 +623,13 @@ from itertools import *
### Combinations ### Combinations
```python ```python
>>> combinations("abc", 2)
>>> combinations('abc', 2)
[('a', 'b'), ('a', 'c'), ('b', 'c')] [('a', 'b'), ('a', 'c'), ('b', 'c')]
``` ```
### Permutations ### Permutations
```python ```python
>>> permutations("abc", 2)
>>> permutations('abc', 2)
[('a', 'b'), ('a', 'c'), ('b', 'a'), ('b', 'c'), ('c', 'a'), ('c', 'b')] [('a', 'b'), ('a', 'c'), ('b', 'a'), ('b', 'c'), ('c', 'a'), ('c', 'b')]
``` ```
@ -641,7 +641,7 @@ from itertools import *
### Compress ### Compress
```python ```python
>>> compress("abc", [True, 0, 23])
>>> compress('abc', [True, 0, 23])
['a', 'c'] ['a', 'c']
``` ```
@ -654,17 +654,17 @@ from itertools import *
### Cycle ### Cycle
```python ```python
>>> a = cycle("abc")
>>> a = cycle('abc')
>>> [next(a) for _ in range(10)] >>> [next(a) for _ in range(10)]
['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a'] ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a']
``` ```
### Groupby ### Groupby
```python ```python
>>> a = [{"id": 1, "name": "bob"},
{"id": 2, "name": "bob"},
{"id": 3, "name": "peter"}]
>>> {k: list(v) for k, v in groupby(a, key=lambda x: x["name"])}
>>> a = [{'id': 1, 'name': 'bob'},
{'id': 2, 'name': 'bob'},
{'id': 3, 'name': 'peter'}]
>>> {k: list(v) for k, v in groupby(a, key=lambda x: x['name'])}
{'bob': [{'id': 1, 'name': 'bob'}, {'bob': [{'id': 1, 'name': 'bob'},
{'id': 2, 'name': 'bob'}], {'id': 2, 'name': 'bob'}],
'peter': [{'id': 3, 'name': 'peter'}]} 'peter': [{'id': 3, 'name': 'peter'}]}
@ -860,7 +860,7 @@ def main():
def draw(screen): def draw(screen):
screen.clear() screen.clear()
screen.addstr(0, 0, "Press ESC to quit.")
screen.addstr(0, 0, 'Press ESC to quit.')
while screen.getch() != 27: while screen.getch() != 27:
pass pass
@ -905,7 +905,8 @@ with pycallgraph.PyCallGraph(output=graph):
#### Utility code for unique PNG filenames: #### Utility code for unique PNG filenames:
```python ```python
def get_filename(): def get_filename():
return "{}-{}.png".format("profile", get_current_datetime_string())
time_str = get_current_datetime_string()
return f'profile-{time_str}.png'
def get_current_datetime_string(): def get_current_datetime_string():
now = datetime.datetime.now() now = datetime.datetime.now()
@ -920,7 +921,7 @@ Audio
#### Saves list of floats of size 0 to 1 to a WAV file: #### Saves list of floats of size 0 to 1 to a WAV file:
```python ```python
import wave, struct import wave, struct
frames = [struct.pack("%dh"%(1), int((a-0.5)*60000)) for a in <list>]
frames = [struct.pack('%dh'%(1), int((a-0.5)*60000)) for a in <list>]
wf = wave.open(filename, 'wb') wf = wave.open(filename, 'wb')
wf.setnchannels(1) wf.setnchannels(1)
wf.setsampwidth(4) wf.setsampwidth(4)

Loading…
Cancel
Save