Created
June 6, 2019 15:03
-
-
Save MoisesTedeschi/62ff6c9c92825ab893b78df586b8d75a to your computer and use it in GitHub Desktop.
Use for, split() e if para criar uma declaração que imprima as palavras que começam com 's'...
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
| st = 'Print only the words that start with s in this sentence' | |
| # Resolvendo de forma normal | |
| new_st_normal = st.split() | |
| for char_normal in new_st_normal: | |
| if char_normal[0] == 's': | |
| print(char_normal) | |
| # Resolvendo com List Comprehensions | |
| new_st = [char for char in st.split() if char[0] == 's'] | |
| print(new_st) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
print([char for char in st.split() if char[0] == 's'])