Skip to content

Commit 8d276a1

Browse files
committed
Completed Day 31
1 parent eeb3701 commit 8d276a1

File tree

9 files changed

+305
-41
lines changed

9 files changed

+305
-41
lines changed

days/19-21-itertools/iter_test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import itertools
2+
3+
names = 'Tim Bob Julian Carmen Sofia Mike Kim Andre'.split()
4+
locations = 'DE ES AUS NL BR US'.split()
5+
confirmed = [False, True, True, False, True]
6+
empty = '- - - - - - -'.split()
7+
loc = itertools.chain(locations, empty)
8+
conf = itertools.chain(confirmed, empty)
9+
10+
11+
def get_attendees():
12+
# for participant in zip(names, locations, confirmed):
13+
# print(participant)
14+
for participants in names:
15+
tupleOut = (participants, next(loc), next(conf))
16+
print(tupleOut)
17+
18+
if __name__ == '__main__':
19+
get_attendees()

days/19-21-itertools/listOfFriends.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import itertools
2+
3+
listOfFriends = 'Mike Sam Tom David'.split()
4+
# team_size = 2
5+
# order_does_matter = False
6+
7+
def friends_teams(listOfFriends, team_size = 2, order_does_matter = False):
8+
if order_does_matter:
9+
my_iter_list = itertools.permutations(listOfFriends, team_size)
10+
11+
12+
else:
13+
my_iter_list = itertools.combinations(listOfFriends, team_size)
14+
15+
print(list(my_iter_list))
16+
17+
# pass
18+
19+
if __name__ == '__main__':
20+
friends_teams(listOfFriends)

days/19-21-itertools/listOfWords.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import itertools
2+
import os
3+
import urllib.request
4+
5+
# PREWORK
6+
DICTIONARY = os.path.join('/tmp', 'dictionary.txt')
7+
urllib.request.urlretrieve('http://bit.ly/2iQ3dlZ', DICTIONARY)
8+
9+
with open(DICTIONARY) as f:
10+
dictionary = set([word.strip().lower() for word in f.read().split()])
11+
12+
print(dictionary)
13+
14+
def get_possible_dict_words(draw):
15+
"""Get all possible words from a draw (list of letters) which are
16+
valid dictionary words. Use _get_permutations_draw and provided
17+
dictionary"""
18+
# pass
19+
permutations = _get_permutations_draw(draw)
20+
print(permutations)
21+
wordList = []
22+
for word in permutations:
23+
if word.lower() in dictionary:
24+
wordList.append(word)
25+
26+
return wordList
27+
28+
29+
def _get_permutations_draw(draw):
30+
"""Helper to get all permutations of a draw (list of letters), hint:
31+
use itertools.permutations (order of letters matters)"""
32+
myList = []
33+
for idx in range(2, len(draw)+1):
34+
myWord = itertools.permutations(draw, idx)
35+
myList += ["".join(a) for a in myWord]
36+
return myList
37+
38+
# ----------
39+
40+
draw = 'G A R Y T E V'.lower().split()
41+
42+
# permutations = _get_permutations_draw(draw)
43+
# print(permutations)
44+
45+
allWords = get_possible_dict_words(draw)
46+
47+
print(allWords)

days/22-24-decorators/decorators.ipynb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@
137137
{
138138
"ename": "TypeError",
139139
"evalue": "get_profile() missing 1 required positional argument: 'name'",
140-
"output_type": "error",
141140
"traceback": [
142141
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
143142
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
144143
"\u001b[0;32m<ipython-input-6-2ef2bb648fe3>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mget_profile\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
145144
"\u001b[0;31mTypeError\u001b[0m: get_profile() missing 1 required positional argument: 'name'"
146-
]
145+
],
146+
"output_type": "error"
147147
}
148148
],
149149
"source": [
@@ -627,7 +627,9 @@
627627
"execution_count": null,
628628
"metadata": {},
629629
"outputs": [],
630-
"source": []
630+
"source": [
631+
"print('test')"
632+
]
631633
}
632634
],
633635
"metadata": {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import time
2+
from functools import wraps
3+
4+
def timeit(func):
5+
''' Decorator to time the function '''
6+
#@wraps (func)
7+
def wrapper(*args, **kwargs):
8+
# before calling the decorated function
9+
print('Starting timer...')
10+
start = time.time()
11+
12+
# Call the decorated function
13+
func(*args, **kwargs)
14+
15+
# After calling the decorated function
16+
end = time.time()
17+
print(f'== {func.__name__} took {int(end-start)} seconds to complete ')
18+
19+
return wrapper
20+
21+
22+
@timeit
23+
def myLoop(x):
24+
for i in range(x):
25+
print(f'i={i}')
26+
27+
28+
# x = input('Please enter range: ')
29+
#
30+
# myLoop(int(x))
31+
32+
33+
def make_html(arg1):
34+
def wrap(func):
35+
def wrapper(*args):
36+
return f'<{arg1}>{func(*args)}</{arg1}>'
37+
return wrapper
38+
return wrap
39+
40+
41+
42+
@make_html('p')
43+
@make_html('strong')
44+
def get_text(text):
45+
return text
46+
#pass
47+
48+
49+
myText = get_text('I code with PiBytes')
50+
51+
print(myText)
Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
import api
2-
2+
import requests.exceptions
33

44
def main():
5-
keyword = 'Python' # input('Keyword of title search: ')
6-
results = api.find_movie_by_title(keyword)
5+
# keyword = 'Python' # input('Keyword of title search: ')
6+
keyword = input('Keyword of title search: ')
7+
8+
try:
9+
results = api.find_movie_by_title(keyword)
10+
11+
print(f'There are {len(results)} movies found.')
12+
for r in results:
13+
print(f"{r.title} with code {r.imdb_code} has score {r.imdb_score}")
14+
15+
except requests.exceptions.ConnectionError:
16+
print('ERROR: check you connection!')
17+
18+
except TypeError:
19+
print('ERROR: Got Type Error!')
20+
21+
except StopIteration:
22+
print('ERROR: We got stop itteration error')
723

8-
print(f'There are {len(results)} movies found.')
9-
for r in results:
10-
print(f"{r.title} with code {r.imdb_code} has score {r.imdb_score}")
24+
except ValueError:
25+
print('ERROR: You must enter the name')
1126

27+
except Exception as x:
28+
print(type(x))
29+
print(f'---- This did not work. error: {x} ----')
1230

1331
if __name__ == '__main__':
1432
main()

days/28-30-regex/regex-test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import re
2+
3+
4+
data = 'Population is 2243603014. The phone number is 224-360-3014. Call me'
5+
6+
phoneRegex = re.compile(
7+
r'\d\d\d-\d\d\d-\d\d\d\d'
8+
)
9+
10+
phoneRegex = re.compile(
11+
r'\d{3}-\d{3}-\d{4}'
12+
)
13+
14+
findPhoneNUmber = phoneRegex.search(data)
15+
phoneRegex.
16+
17+
print(findPhoneNUmber.group())
18+

0 commit comments

Comments
 (0)