Created
September 14, 2019 13:53
-
-
Save dradecic/9f23eb0c8073ecc8957f8fd533388cef to your computer and use it in GitHub Desktop.
art7_list_comprehensions
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
titles = [ | |
'This is a text without question mark', | |
'I contain question mark at the end?', | |
'No question mark for me...', | |
'What? A question mark? Sure.' | |
] | |
results = [] | |
for title in titles: | |
if '?' in title: | |
results.append(1) | |
else: | |
results.append(0) | |
print(results) # [0, 1, 0, 1] | |
# List Comprehensions | |
[1 if '?' in title else 0 for title in titles] # [0, 1, 0, 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment