0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

めざせpythonライブラリマスター (25)orderedset

Last updated at Posted at 2016-06-04

#【ライブラリ説明】
 集合を簡単に扱える

#【準備】
 python2.7ではインストール時にエラーが出たため、python3.5を使用

#【プログラム】

orderedset.py
# -*- coding: utf-8 -*-

from orderedset import OrderedSet

oset = OrderedSet([1, 2, 3])
oset2 = OrderedSet([3, 2, 1])
oset3 = OrderedSet([1, 2, 3, 4])

print (oset == oset2)
# False
print (oset <= oset2)
# True

# 部分集合かどうか
print (oset.isorderedsubset(oset2))
# False
print (oset.isorderedsubset(oset3))
# True

oset = OrderedSet([1, 2, 3])
lst = [1, 2, 3]
tes = {1, 2, 3, 4}

print (oset == lst)
# True
print (oset <= tes)
# True

print (oset | lst)
# OrderedSet([1, 2, 3])
print (oset | tes)
# OrderedSet([1, 2, 3, 4])

#【参考サイト】
 document

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?