- 创建一个列表,列表中有10个数字, 保证列表中元素的顺序,对列表进行排重,并对列表使用进行降序排序
list1 = [70, 88, 91, 70, 107, 234, 91, 177, 282, 197]
new_list1 = []
for x in list1:
if x not in new_list1:
new_list1.append(x)
new_list1 = sorted(new_list1, reverse=True)
print(new_list1)
- 利用列表推导式, 完成以下需求
a. 生成一个存放1-100中个位数为3的数据列表
list1 = [x for x in range(1, 100) if x % 10 == 3 ]
print(list1)
b. 利用列表推导式将 列表中的整数提取出来
list1 = [True, 17, "hello", "bye", 98, 34, 21]
new_list1 = [x for x in list1 if type(x) == int