Parsing with Python -
i attempting parse file. currently, have file:
word1 52345325 word2 12312314 word3 7654756 word4 421342342
i attempting store word1
word2
word3
, word4
array , numbers adjacent words array.
so if a[0]
should word1
, , if b[0]
should 52345325
, on.
i thinking making key-valued pair dictionary object may little complex @ point getting python.
i doing of course, ain't working :p
def csvstringparser(): = {} b = {} = 0 f = open('/users/settingj/desktop/noxmultiplier.csv') line in f.readlines(): reader = csv.reader(line.split('\t'), delimiter='\t') row in reader: #print '\t'.join(row) #print a[i] = '\t'.join(row) b[i] = '\t'.join(row) print a[i] print b[i] i+=1
this first hour of using python. in c++ i'm trying learn python understand it's greater benefits/simplicity on c++.
import csv = {} open('/users/settingj/desktop/noxmultiplier.csv') f: reader = csv.reader(f, delimiter='\t') row in reader: a[row[0]] = row[1] print
for 2 arrays:
a = [] b = [] open('/users/settingj/desktop/noxmultiplier.csv') f: reader = csv.reader(f, delimiter='\t') row in reader: a.append(row[0]) b.append(row[1]) print print b
of similar solution zip:
with open('/users/settingj/desktop/noxmultiplier.csv') f: a, b = zip(*csv.reader(f, delimiter='\t')) print print b
Comments
Post a Comment