I have a file with data:
ABC acd IGK EFG
GHQ ghq acb efg
IJK ijk gtt ttg
I want to split its lines and take some data from each line and join them into a list. Like this:
a = ['acd', 'ghq', 'ijk']
So far I have done following.
li = []
with open('file.txt') as fl:
for f in fl:
f = f.split()
li = li.append(f[2])
But I am getting the following error:
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
AttributeError: 'NoneType' object has no attribute 'append'
Can someone please help me in completing the code?
list
s anddict
s that change it in-place, such aslist.append()
anddict.clear()
, don't return the object being changed. They effectively returnNone
.