Question Description
网上查询到去掉list中的重复元素的主流方法为使用set()
来去重,即
|
|
这样得到的list_after
为[1,2,3],但是如果list_before里包括list,比如list_before = [1,2,[3],[3]]
还用上述方法的话就会报错:
|
|
错误为:list是不能哈希的
Solution
用简单的两个for循环即可解决该问题。
|
|
网上查询到去掉list中的重复元素的主流方法为使用set()
来去重,即
|
|
这样得到的list_after
为[1,2,3],但是如果list_before里包括list,比如list_before = [1,2,[3],[3]]
还用上述方法的话就会报错:
|
|
错误为:list是不能哈希的
用简单的两个for循环即可解决该问题。
|
|
近期评论