标签:李宁 png lis 推导式 alt str pos img ble
补写list3被涂改的内容
结果如下:
1 list1 = ["1.Just do it", "2.一切皆有可能", "3.让编程改变世界", "Impossible is Nothing"] 2 list2 = ["4.阿迪达斯", "2.李宁", "3.python", "1.耐克"] 3 list3 = [name + ":" + slogan[2:] for slogan in list1 for name in list2 if slogan[0]==name[0]] 4 5 print(list3) 6 for each in list3: 7 print(each)
列表推导式还原如下:
1 list1 = ["1.Just do it", "2.一切皆有可能", "3.让编程改变世界", "Impossible is Nothing"] 2 list2 = ["4.阿迪达斯", "2.李宁", "3.python", "1.耐克"] 3 for slogan in list1: 4 #遍历list1内容 获取口号slogan 5 for name in list2: 6 #遍历list2内容 获取品牌name 7 if name[0] == slogan[0]: 8 #如果name里下标0的字符与slogan里下标0的字符相同 9 list3 = name + ":" + slogan[2:] 10 #进行加法和切片 11 print(list3)
标签:李宁 png lis 推导式 alt str pos img ble
原文地址:https://www.cnblogs.com/98ZHANG/p/11385563.html