Python dictionary with len(20) compare to list with range(7804) -
i have been trying convert xml file csv file format. , have little problem. if else statement of printing csv files.
this have
i have dictionary len of 20.
rankings{4706: '8.185', 2358: '0.444', 6245: '0.851', 615: '0.444', 7626: '2.164', 2219: '0.315', 4338: '0.348', 3790: '0.876', 6194: '0.362', 2228: '0.541', 597: '0.495', 6838: '3.883', 4567: '1.173', 7800: '0.521', 3796: '0.326', 2042: '5.076', 5141: '0.316', 1722: '0.595', 5566: '0.555', 1429: '0.435'}
and have few list 7804 big.
eventidlist = [] artkeylist = [] languageall = [] startdatetime = [] enddatetime = [] sentenceid = [] sentencecontent = []
i utilize dictionarykey compare eventidlist if it's same, print value of key csv file.
so have tried using
for in rankings: in range(7804): if(int(a) == int(eventidlist[i])): csvfile.write(eventidlist[i] + ',' + ...... +',' + rankings[a]) else: csvfile.write(eventidlist[i] + ',' + ..... + ',' + " "(rankings) + ',' + sentencecontent[i])
the problem programme go through if statement. still need go through else statement.
any thought went wrong in codes?
if arrays have same length, , output must line per array position, loop should this
eventidlist = range(7804) sentencecontent = range(7804) rankings = {4706: '8.185', 2358: '0.444', 6245: '0.851', 615: '0.444', 7626: '2.164', 2219: '0.315', 4338: '0.348', 3790: '0.876', 6194: '0.362', 2228: '0.541', 597: '0.495', 6838: '3.883', 4567: '1.173', 7800: '0.521', 3796: '0.326', 2042: '5.076', 5141: '0.316', 1722: '0.595', 5566: '0.555', 1429: '0.435'} idx in range(len(eventidlist)): if rankings.get(idx,'') , eventidlist[idx] == rankings.get(idx,''): csvfile.write( "%i, %s" % (eventidlist[idx] , rankings[idx])) else: csvfile.write( "%i, %i" % (eventidlist[idx] , sentencecontent[idx]))
python dictionary
No comments:
Post a Comment