Skip to content

Instantly share code, notes, and snippets.

@scandiumby
Last active February 21, 2019 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scandiumby/d5728572bc5901805197f11d3a6da091 to your computer and use it in GitHub Desktop.
Save scandiumby/d5728572bc5901805197f11d3a6da091 to your computer and use it in GitHub Desktop.
Bad example for use map/lambda in Python3
in_list = [1, 2, 3, 4, 5]
out_list = list(map(lambda x: (x + 1) if x % 2 == 0 else x, in_list))
print(out_list)
@scandiumby
Copy link
Author

Nice solution:

in_list = [1, 2, 3, 4, 5)
for i in range(len(in_list)):
    if in_list[i] % 2 == 0:
        in_list[i] += 1
print(out_list)

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