各位大哥帮帮忙呗,小弟实在是看不懂呀
https://xxx.ilovefishc.com/forum/201310/12/044035qddrqkmrqod4cqmr.png>>> list3 = for slogan in list1 for name in list2 if slogan == name]
谁能帮忙解释解释{:5_104:}
是解释这句话吗:
list3 = for slogan in list1 for name in list2 if slogan == name]
意思是list3的元素由name:slogan组成;name在list2里,slogan在llist1里;name和slogan的匹配规则:name里的字符串元素首和slogan里的元素字符串首位匹配。
slogan的意思是slogan里的元素只取前两位以后的,即去掉了数字开头和英文的点,比如“1.” 以下两者代码相同意思
示例 1:A = ['1', '2', '3']
B = ['a', 'b', 'c']
C =
print(C)['1:a', '1:b', '1:c', '2:a', '2:b', '2:c', '3:a', '3:b', '3:c']示例 2:A = ['1', '2', '3']
B = ['a', 'b', 'c']
C = []
for x in A:
for y in B:
C.append(x + ':' + y)
print(C)['1:a', '1:b', '1:c', '2:a', '2:b', '2:c', '3:a', '3:b', '3:c']
希望对你有帮助{:5_105:} 看看这个,也许你会明白。
地址:https://blog.csdn.net/lexi3555/article/details/80633441
页:
[1]