有如下列表对象:
my_list = [‘程序员’, ‘黑客’, ‘程序员’, ‘黑客’, ‘itheima’, ‘itcast’, ‘itheima’, ‘itcast’, ‘best’]
请:
定义一个空集合
通过for循环遍历列表
在for循环中将列表的元素添加至集合
最终得到元素去重后的集合对象,并打印输出
my_list = ['程序员', '黑客', '程序员', '黑客', 'itheima', 'itcast', 'itheima', 'itcast', 'best']
print(f'原列表为:{my_list}')
my_set = set()
for element in my_list:
my_set.add(element)
print(f'现集合为:{my_set}')