Skip to content

Instantly share code, notes, and snippets.

@sungiven
Last active January 27, 2024 18:31
Show Gist options
  • Save sungiven/ec283af747996911274732864f486e84 to your computer and use it in GitHub Desktop.
Save sungiven/ec283af747996911274732864f486e84 to your computer and use it in GitHub Desktop.
listcomp list vs filter/map composition
#!/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