说我有这两个清单:
list1=["Green","2","Blue","4"]
list2=["1","Orange","3","red"]
如果我想将'3'与'blue'交换,如果我不知道列表中元素的位置,我该怎么办?
我正在使用Python 2.7
答案 0 :(得分:2)
list1=["Green","2","Blue","4"]
list2=["1","Orange","3","red"]
l1 = list1.index("Blue")
l2 = list2.index("3")
list1[l1], list2[l2] = list2[l2], list1[l1]