Is there a result:

test 1:4 a1, a1_2, a1_3, a2, a2_2 

Need to find in the second column:

 a1 3 a1_2 4 a1_3 5 a2 5 a2_2 7 

And to get:

 test 1:4 3,4,5,5,7 
  • What has been done, what thoughts? - skegg
  • that's it not what) Nothing comes to mind. There is one in the first script to collect a new dictionary. type test 1: 4 a1 test 1: 4 a1_2 and continue to process - avdoshkin
  • Second convert to dictionary and then convert first - alexlz
  • What are your columns, what kind of python structures are lists? Or just a thong? - moden

1 answer 1

Maybe so?

 import re firstline = re.split(r'\s*[, ]\s*', input()) d = {} try: while True: [l1, l2] = input().split() d[l1] = l2 except EOFError: f = [] for i in firstline[2:] : f.append(d[i]) firstline = firstline[:2] firstline.append(','.join(f)) print(' '.join(firstline)) 

UPD Fixed regular expression r'\s*,?\s*' on r'\s*[, ]\s*' . Nervous about the fact that the initial expression satisfies the empty string.

  • I rewrote my script and everything turned out, I was too lazy to rewrite, I wanted to cross the output from two scripts) - avdoshkin
  • Thanks to all! - avdoshkin 2:44