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
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
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.
Source: https://ru.stackoverflow.com/questions/160676/
All Articles