Skip to content

Instantly share code, notes, and snippets.

@altela
Last active May 7, 2022 02:18
Show Gist options
  • Save altela/42686e68454e697d0a7ff9ef4191b4fc to your computer and use it in GitHub Desktop.
Save altela/42686e68454e697d0a7ff9ef4191b4fc to your computer and use it in GitHub Desktop.
Python FOR Iteration tricks
# Add character inside list
list_numbers = ['001','002','003']
add_percent = [pulled + "%" for pulled in list_numbers]
print(add_percent)
# The result will be ['001%','002%','003%']
# Split each words with space
# Example 1
the_string = 'silly walks'
for ix in range(len(the_string)):
print(the_string[ix], end=' ')
print(ix)
# Example 2
the_string = 'silly walks'
for words in the_string :
print(words, end=" ")
print(words)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment