I want to append words to a list. If I conduct a for loop the answers returned are correct.
However, if I conduct a list comprehension method I get None for the answers. What am I doing wrong?
x=[]
for i in range(0,10):
x.append('hi'+str(i))
print(x)
Answer : ['hi0', 'hi1', 'hi2', 'hi3', 'hi4', 'hi5', 'hi6', 'hi7', 'hi8', 'hi9']
x= [x.append('hi'+str(i)) for i in range(0,10)]
print(x)
Answer : [None, None, None, None, None, None, None, None, None, None]