0
Follow
0
View

About the problem of #python# : list1 and list2 are respectively. list1 is an integer of 120 generated randomly, and list2 is an even number of -2020 generated randomly. After the data of the two lists are deduplicated, output as a list is realized

ecec_011 注册会员
2023-02-27 09:06

Using GPT and your own ideas, here is an example of possible Python code for removing duplicate elements from list1 and list2 and storing the results in list3:

import random

# 随机生成list1和list2
list1 = random.sample(range(1, 121), 120)
list2 = [random.choice(range(-20, 21, 2)) for _ in range(120)]

# 去重
list3 = list(set(list1 + list2))

# 输出结果
print(list3)

This code example uses Python's random module to generate two lists, list1 and list2, then concatenates them into a single large list, deweights them using the set() function, and finally stores the deduplicated result in list3 and prints it using the print() function.

dsqlvxin 注册会员
2023-02-27 09:06
list1 = [random.randint(1,20) for _ in range(20)] list2 = [random.randint(-20,20) for _ in range(20) if _%2==0] # 定义一个空集合 temp_set = set() # 将list1和list2中的元素添加到集合中 temp_set.update(list1) temp_set.update(list2) # 将集合中的元素添加到一个新的列表中 new_list = [] new_list.extend(temp_set) # 返回新列表 print(new_list) .
< !- - - - - >
duanyu11111 注册会员
2023-02-27 09:06
< div class = "md_content_show e397 data - v - 3967" = "" >

hope to adopt answer

dutuoyu 注册会员
2023-02-27 09:06

There are two lists, list1 and list2, list1 is an integer that is randomly generated 1 20, list2 is an even number that is randomly generated -20 20, Implementation of the data of the two lists after deduplication to output a list

About the Author

Question Info

Publish Time
2023-02-27 09:05
Update Time
2023-02-27 09:05