set in Java/Python/Go/Javascript

2015-01-29 KasperDeng 更多博文 » 博客 » GitHub »

programming

原文链接 https://kasperdeng.github.io/SetInJavaPythonGoJS/
注:以下为加速网络访问所做的原文缓存,经过重新格式化,可能存在格式方面的问题,或偶有遗漏信息,请以原文为准。


Set Java Python Go
type Set<...>, HashSet, etc set N/A
package import Set primitive N/A
mutable Y Y N/A

Notes

  • Set is not sequence, cannot be got by index and slicing
  • python
    • frozenset is immutable set
  • go
    • No primitive set and related lib

Operations


### python ###

# create
demoset = set()
demoset = set(list) # input args is sequence
demoset.add(element)

# retrieve
demoset.pop()

# update
demoset.update(other_set) # merge

# delete
demoset.remove(element)
demoset.discard(element)

# others
&, |, -, ^
==, !=, >, >=, <, <=