Home > other >  Help to have a look at this problem
Help to have a look at this problem

Time:09-16

CodePudding user response:

Probably this step,

1, read the A2. TXT
Build a dictionary students={' 41900001 ': [' Angela],' 41900002 ': [' Chen']}

2, read B2. TXT

List your homework to the students,

Students={' 41900001 ': [' Angela' [' 3 ', '4', '1', '2', '5']], '41900002' : [' Chen ', '3', '2', '5', '4', '1', '6']}

3, processing jobs list, you can use the set to heavy, to list sorting,

4, the output

CodePudding user response:

 import more_itertools as mi 

Path1=r 'c: \ A2. TXT'
Path2=r 'c: \ B2. TXT'
With the open (path1, encoding="utf-8") as f:
L1=f.r ead (.) splitlines ()
L1=[_. The split (', ') for _ in l1]
D1={a, b for a, b in l1}
With the open (path2, encoding="utf-8") as f:
L2=f.r ead (.) splitlines ()
L2=[[_ [(_. Find (', '))], _ [(_), find (', ')) + 1:]. The split (', ')] for _ in l2]
L2. Sort (key=lambda x: x [0])
G=mi. Groupby_transform (l2, keyfunc=lambda x: x [0], valuefunc=lambda x: set (x) [1])
G={a: list (set (mi. The collapse (b))) for a, b in g}
D2={k: ', '. Join (sorted (v)) for k, v in g.i tems ()}

Result=[k + + v + ', '+' 'd2. Get (k,' no ') for k, v in d1. The items ()]
Print (result)
  • Related