题解 | #数据分类处理#
数据分类处理
https://www.nowcoder.com/practice/9a763ed59c7243bd8ab706b2da52b7fd
一个for循环就搞定了吧,为啥题解都写那么复杂
i_ls = list(input().strip().split(' '))[1:]
r_ls = list(input().strip().split(' '))[1:]
r_ls = list(sorted(set(r_ls), key=lambda x:int(x)))
res = []
for i in r_ls:
temp = [(jdx, j) for jdx, j in enumerate(i_ls) if i in j]
if temp:
res.extend([i,len(temp)])
for temp_jdx, temp_j in temp:
res.extend([temp_jdx,temp_j])
print(' '.join(list(map(str, [len(res)] + res))))