Python dictionary of lists from tab delimited file -
i'm attempting load tab delimited text file python program. has next format,
aaaaaa 1234 5678 90ab qqqq jkl1 bbbbbb qwer tyui asdf qqqq cccccc zxcv 1234 pppp ... zzzzzz 1111
in short, variable numbers of columns each row, @ to the lowest degree 2 , each column within row unique. first column utilize key, , load rest list key pointing it. tried looking csv module suggested in other threads, i've not quite found way create work me. yeah, apologies if should more obvious, much newbie question.
simple str.split
should work fine splitting columns. using that, need read each row , split columns taking first element key , rest value:
with open(file) fin: rows = ( line.split('\t') line in fin ) d = { row[0]:row[1:] row in rows }
python list csv dictionary
No comments:
Post a Comment