Skip to content

Commit 2522f5c

Browse files
committed
Add python answers
1 parent 0fb14b9 commit 2522f5c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,18 @@ PEP8 is a list of coding conventions and style guidelines for Python
17071707

17081708
```
17091709
Shortest way is <code>str[::-1]</code> but not the most efficient.
1710+
1711+
"Classic" way:
1712+
1713+
foo = ''
1714+
1715+
for char in 'pizza':
1716+
foo = char + foo
1717+
1718+
>> 'azzip'
1719+
17101720
```
1721+
17111722
</b></details>
17121723

17131724
<details>
@@ -1732,10 +1743,12 @@ Shortest way is <code>str[::-1]</code> but not the most efficient.
17321743

17331744
<details>
17341745
<summary>How to write to a file?</summary><br><b>
1746+
17351747
```
17361748
with open('file.txt', 'w') as file:
17371749
file.write("My insightful comment")
17381750
```
1751+
17391752
</b></details>
17401753

17411754
<details>
@@ -1757,8 +1770,22 @@ sorted(x, key=lambda l: l[1])
17571770
Extract all type of foods. Final output should be: {'mushrooms', 'goombas', 'turtles'}</summary><br><b>
17581771

17591772
```
1773+
brothers_menu = \
1774+
[{'name': 'Mario', 'food': ['mushrooms', 'goombas']}, {'name': 'Luigi', 'food': ['mushrooms', 'turtles']}]
1775+
1776+
# "Classic" Way
1777+
def get_food(brothers_menu) -> set:
1778+
temp = []
1779+
1780+
for brother in brothers_menu:
1781+
for food in brother['food']:
1782+
temp.append(food)
1783+
1784+
return set(temp)
1785+
17601786
set([food for bro in x for food in bro['food']])
17611787
```
1788+
17621789
</b></details>
17631790

17641791
<details>

0 commit comments

Comments
 (0)