# coding=utf-8 """ 有两个集合 one = [ 'a1', 'a2', 'a3', 'b1', 'c1', 'c2', 'f1', 'j1'] two = ['A1', 'A2', 'B1', 'B2', 'C1', 'E1'] 首字母映射,输出如下结果: a1, a2, a3 --- A1, A2 b1 --- B1, B2 c1, c2 --- C1 """ def test(): one = ['a1', 'a2', 'a3', 'b1', 'c1', 'c2', 'f1', 'j1'] two = ['A1', 'A2', 'B1', 'B2', 'C1', 'E1'] one_0 = [] two_0 = [] for i in range(0, len(one)-1): if one[i+1][0] == one[i][0]: one_0.append(one[i]) else: one_0.append(one[i]) for j in range(0, len(two)-1): if two[j + 1][0] == two[j][0]: two_0.append(two[j]) else: two_0.append(two[j]) if one[i][0].upper() == two[j][0]: print ", ".join(one_0) + " --- " + ", ".join(two_0) two_0 = [] one_0 = [] if __name__ == '__main__': test()
集合映射
猜你喜欢
转载自blog.csdn.net/MiaoDaLengShui/article/details/64442159
今日推荐
周排行