python 设置更新列表或设置(列表)

标签 python list set iterable

我遇到了如下代码

l = [1, 2]
s = set()
# the same results from the following two
s.update(set(l))    
s.update(l)

为什么这两个得到相同的结果?是因为两者都是可迭代的吗?

最佳答案

Documentation :

Note, the non-operator versions of update(), intersection_update(), difference_update(), and symmetric_difference_update() will accept any iterable as an argument.

关于python 设置更新列表或设置(列表),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44070238/

相关文章:

c++ - std::set 为什么比 std::map 慢?

Python 字典打印所有键的所有值

python - 编写优秀的 Twisted 网络资源

python - python 中可扩展返回对象的最佳方法

带有 Office 2013 (office 15) 的 Python Makepy

python - 列表总是被重置?

java - 从另一个类方法调用对象数组的特定成员

delphi - 如何检查子集是否包含在集合中?

java - Hibernate ManyToMany 方法抛出 'org.hibernate.LazyInitializationException' 异常

python - 如何为 "scipy.interpolate.make_lsq_spline"选择好的结序列