I have a list in python, which is from a text document that I split at new line characters. The end of data is indicated with # in the text document. I need to count each of element of the list and then split the strings in the list at tab characters, creating a two dimensional list.
I thought this was fairly simple, however, I'm not getting a result from my code. The strings in the list are not splitting at all, nevermind at \t.
with open('names.txt') as names:
records = names.read().split('\n')
recordcount = 0
for item in records:
if item != '#':
recordcount += 1
item = item.split('\t')
print (records)
print (recordcount)
Has this got something to do with tab characters being troublesome? Or can I not replace elements of a list in-place? Should I be creating a new list with my split records?