Skip to content

Python map() and lambda #8

Open

Description

@igoose1

<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! 👍

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions