题解 | #数据分类处理#

数据分类处理

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))))

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务