I am trying to understand when should one use list comprehension. a lot of time, it is convenient and save lines. But sometimes, it does not work as expected?
if I have:
listA = ['1', '2', '3', '4']
I can use a for loop
for i in listA:
print(i)
obviously this will give me:
1
2
3
4
what if I try:
print(i for i in listA)
but this won't give me the same result?
<generator object <genexpr> at 0x102a3b3b8>
How should I understand this?
My additional question is: if I have a for loop followed by one line of codes, can one always write it in a way using comprehension?