-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
python-vs-javascript/index.html
Lines 1267 to 1275 in 444a7ab
| <pre><code class="language-python">original_list = [1, 2, 3] | |
| new_list = [x * 2 for x in original_list] | |
| # 2 | |
| # 4 | |
| # 6 | |
| for x in new_list: | |
| print(x) | |
| </code></pre> |
In python there is an easier way to multiple each element in list:
original_list = [1, 2, 3]
new_list = list(map(lambda x: x * 2, original_list))
for x in new_list:
print(x)Imo, this example is more similar to js example because there is map function that exists in python too.
Unfortunately my example is difficult for understanding but we can split it for more lines:
original_list = [1, 2, 3]
f = lambda x: x * 2
new_list = list(map(f, original_list))
for x in new_list:
print(x)Thank you for your repository! I'm glad to meet it in github's recommendations! 👍
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels