Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Note that this solution doesn't rely on the lengths of any field except for the length of the file extension in the second file.</p> <pre><code># make a dict keyed on the filename before the extension # with the other two fields as its value file2dict = dict((row[0][:-4], row[1:]) for row in (line.split() for line in file2)) # then add to the end of each row # the values to it's first column output = [row + file2dict[row[0]] for row in (line.split() for line in file1)] </code></pre> <p>For testing purposes only, I used:</p> <pre><code># I just use this to emulate a file object, as iterating over it yields lines # just use file1 = open(whatever_the_filename_is_for_this_data) # and the rest of the program is the same file1 = """12319000 -64,7357668067227 -0,1111052148685535 12319000 -79,68527661064425 -0,13231739777754026 12319000 -94,69642857142858 -0,15117839559513543 12319000 -109,59301470588237 -0,18277783185642743 12319001 99,70264355742297 0,48329515727315125 12319001 84,61113445378152 0,4060446341409862 12319001 69,7032037815126 0,29803063228455073 12319001 54,93886554621849 0,20958105041136763 12319001 39,937394957983194 0,13623056582981297 12319001 25,05574229691877 0,07748669438398018 12319001 9,99716386554622 0,028110643107892755""".splitlines() # again, use file2 = open(whatever_the_filename_is_for_this_data) # and the rest of the program will work the same file2 = """12319000.abf mutant 1 12319001.abf mutant 2 12319002.abf mutant 3""".splitlines() </code></pre> <p>where you should just use normal file objects. The output for the test data is :</p> <pre><code> [['12319000', '-64,7357668067227', '-0,1111052148685535', 'mutant', '1'], ['12319000', '-79,68527661064425', '-0,13231739777754026', 'mutant', '1'], ['12319000', '-94,69642857142858', '-0,15117839559513543', 'mutant', '1'], ['12319000', '-109,59301470588237', '-0,18277783185642743', 'mutant', '1'], ['12319001', '99,70264355742297', '0,48329515727315125', 'mutant', '2'], ['12319001', '84,61113445378152', '0,4060446341409862', 'mutant', '2'], ['12319001', '69,7032037815126', '0,29803063228455073', 'mutant', '2'], ['12319001', '54,93886554621849', '0,20958105041136763', 'mutant', '2'], ['12319001', '39,937394957983194', '0,13623056582981297', 'mutant', '2'], ['12319001', '25,05574229691877', '0,07748669438398018', 'mutant', '2'], ['12319001', '9,99716386554622', '0,028110643107892755', 'mutant', '2']] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload