1.对以下列表数据进行去重
L = [1, 2, 3, 11, 2, 5, 3, 2, 5, 3]
L1 = list(set(L))
print(L1)
2.下列表数据,如何使数据变成123456?
L = [1, 2, 3, 4, 5, 6]
s = ''
for i in L:
s = s + str(i)
print(s)
print(type(s))
3.等长的俩个列表要求合并到一个字典中
keys = ["A", "B", "C"]
values = ["1", "2", "3"]
print(dict(zip(keys, [int(x) for x in values])))
4.将俩个列表进行合并,并消除重复值
list_1 = ['a', 'b', 'c', '1', 'A', 'winning']
list_2 = ['a', 'python', 'string']
print(set(list_1 + list_2))
5.小明有一百元,他想买一百本书,英语书5元一本,数学书3元一本,语文书0.5元一本,请问他有多少种买法?
问题分析:
100块钱,单独可以买20本英语书,33本数学书,200本语文书,但是也可以进行组合,可以通过for循环来实现,i=英语书,j=数学书,k=语文书
n = 0
for i in range(21):
for j in range(34):
for k in range(201):
if 5 * i + 3 * j + k * 0.5 <= 100 and i + j + k == 100:
n += 1
print(n)
|