Created
January 27, 2024 09:22
-
-
Save sungiven/db5ccf54f961c9c8d2d378ef9125876f to your computer and use it in GitHub Desktop.
listcomp comparison
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 = "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