Skip to content

Instantly share code, notes, and snippets.

@sungiven
Created January 27, 2024 09:22
Show Gist options
  • Save sungiven/db5ccf54f961c9c8d2d378ef9125876f to your computer and use it in GitHub Desktop.
Save sungiven/db5ccf54f961c9c8d2d378ef9125876f to your computer and use it in GitHub Desktop.
listcomp comparison
#!/usr/bin/env python3
symbols = "fj92hf!TGgq2^#"
# without using listcomp
codes = []
for symbol in symbols:
codes.append(ord(symbol))
print(codes)
# using listcomp
codes = [ord(symbol) for symbol in symbols]
print(codes)
"""
Output:
[102, 106, 57, 50, 104, 102, 33, 84, 71, 103, 113, 50, 94, 35]
[102, 106, 57, 50, 104, 102, 33, 84, 71, 103, 113, 50, 94, 35]
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment