When i execute the below code, i get the right results:
for i in quorum:
lst.append(i.strip('l'))
print lst
op:
['val1', 'val2', 'val3']
but when i try to have the for loop along with list append function in single line, i don't get the expected output (i.e the list elements as above).
what am i missing ? and why does it behave that way ?
lst.append(i.strip('l') for i in quorum)
print lst
op:
[<generator object <genexpr> at 0x2996cd0>]
list.extendmethod.list.appendadds argument to list, in your case iterable (generator expression) itself.