Original Syntax:
word = "apple"
letters = [word[i] for i in range(len(word))]
print(letters)
I recently stumbled on the above syntax that outputs a list containing all the characters in a string
I am a beginner and have not understood how this type of syntax works.
I know how list splicing works and am familiar with the range() and len() methods. But so far in my learning, I have only seen the standard syntax with regards to for loops.
For instance, the below code prints all the characters on a new line
for i in range(len(word)):
print(word[i])
Could anyone help me understand how the original syntax works or guide me to the relevant documentation?