Last active
January 27, 2024 18:31
-
-
Save sungiven/ec283af747996911274732864f486e84 to your computer and use it in GitHub Desktop.
listcomp list vs filter/map composition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
symbols = "fj#@2$¢£¥€¤92f^x" | |
over_ascii = [ord(s) for s in symbols if ord(s) > 127] | |
print(over_ascii) | |
# Using filter/map composition to make the same list created by the listcomp looks | |
# so much more complex. | |
over_ascii = list(filter(lambda c: c > 127, map(ord, symbols))) | |
print(over_ascii) | |
# output: | |
# [162, 163, 165, 8364, 164] | |
# [162, 163, 165, 8364, 164] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment