to read file and compare column in python -


for example: consider contents of file1.txt:

1   0   9227    1152    34  2 2   111 7622    1120    34  2 3   68486   710 1024    14  2 6   265065  3389    800 22  2 7   393152  48438   64  132 3 8   412251  46744   64  132 3 9   430593  50866   256 95  4 10  430730  10770   256 95  4 11  433750  12701   256 14  3 12  437926  2794    64  34  2 13  440070  43  32  96  3 14  440102  44  32  96  3 15  440357  43  32  96  3 16  440545  43  32  96  3 17  440599  43  32  96  3 18  440625  43  32  96  3 19  440999  84  32  96  0 20  441574  44  32  96  3 ````````````````````````````````````````` ````````````````````````````````````````` ````````````````````````````````````````` ````````````````````````````````````````` ````````````````````````````````````````` ````````````````````````````````````````` 

which contains n jobs 6 fields(i,e column(0-5))

now, example, take first 19 jobs history. need start reading 20th , on comparing columns 3,4,5 matches above jobs in history. if in example 20th job matches 6(13,14,15,16,17,18) 6 jobs in history need create list of matching jobs containing column2?.

can 1 suggest code in python possible me read 20st line , compare above history , continue 21,22,23------------------ until end of file reached......

check if works you:

>>> history = {} >>> historycount = 17 >>> line in open("filename"):     job = line.split()     jobmatch_criteria = '-'.join(job[-3:])     if historycount > 0:         history.setdefault(jobmatch_criteria,[]).append(job)         historycount -= 1     else:         print "job", job[0], "matched with:", '\n\t'.join(' '.join(i) in history[jobmatch_criteria]) if jobmatch_criteria in history else "none"   job 20 matched with: 13 440070 43 32 96 3     14 440102 44 32 96 3     15 440357 43 32 96 3     16 440545 43 32 96 3     17 440599 43 32 96 3     18 440625 43 32 96 3 job 21 matched with: 6 265065 3389 800 22 2 

i used test data:

1   0   9227    1152    34  2 2   111 7622    1120    34  2 3   68486   710 1024    14  2 6   265065  3389    800 22  2 7   393152  48438   64  132 3 8   412251  46744   64  132 3 9   430593  50866   256 95  4 10  430730  10770   256 95  4 11  433750  12701   256 14  3 12  437926  2794    64  34  2 13  440070  43  32  96  3 14  440102  44  32  96  3 15  440357  43  32  96  3 16  440545  43  32  96  3 17  440599  43  32  96  3 18  440625  43  32  96  3 19  440999  84  32  96  0 20  441574  44  32  96  3 21  265065  3389    800 22  2 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -