I should use these more often, they certainly happen a lot with geometric coding.
convenient comparison inside list comprehension
This file contains hidden or 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
# convenient comparisons | |
for i in range(30): | |
if 20 <= i <= 25: | |
print(i) | |
""" | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
""" |
This file contains hidden or 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
# convenient comparison inside list comprehension | |
valid_list = [i for i in range(30) if (20 <= i <= 25)] | |
print(valid_list) | |
""" | |
[20, 21, 22, 23, 24, 25] | |
""" |