l1 = [11,22,33]
l2 = [22,33,44]
# 1、获取内容相同的两个元素
# 2、获取l1中有l2没有的元素
# 3、获取l2中有l1中没有的元素
# 4、获取l1 l2中内容都不通的元素
1、for i in l1:
for a in l2:
if i == a:
print(a)
2、for i in l1:
if i not in l2:
print(i)
3、for i in l2:
if i not in l1:
print(i)
4、for i in l1:
if i not in l2:
print(i)
for i in l2:
if i not in l1:
print(i)
# 1 2 3 4 5 6 7 8这8个数能组成多少互不相同且没有重复数字的两位数?
count = 0
for i in range(1,9):
for a in range(1,9):
if i != a:
count += 1
print(count)
另一种方法:根据索引来确定范围
li = [1,2,3,4,5,6,7,8]
l = len(li)
for i in range(0,l-1):
for v in range (i+1,l):
print(li[i],li[v])
# a:计算元组长度
# b:获取元组的第二个元素
# c:获取元组的第1-2个元素
# d:使用for输出元组的元素
# e:使用for len range输出元组的索引
# f:请使用ennumber输出元组元素和序号(序号从10开始)
# a: print(len(li))
# b: print(li[1])
# c: print(li[1:3])
# d: for i in li:
# print(i)
# e: for i in range(len(li)):
# print(i)
# f: for i,v in enumerate(li,10):
# print(i,v)
# 列表中任意两个元素相加等于9的元素集合
#
# nums = [2,7,11,1,8,4,5]
# # a = []
# # for i in nums:
# # for v in nums:
# # if i + v == 9:
# # a.append((i,v))
# # print(a)
#
# #取数的索引值
# a = []
# for i in range(len(nums)):
# for v in range(len(nums)):
# if nums[i] + nums[v] == 9:
# a.append((i,v))
# print(a)