Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
f04fa1bc
Kaydet (Commit)
f04fa1bc
authored
Nis 08, 2009
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add docstrings.
üst
d1b3de36
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
0 deletions
+29
-0
collections.py
Lib/collections.py
+29
-0
No files found.
Lib/collections.py
Dosyayı görüntüle @
f04fa1bc
...
...
@@ -36,6 +36,11 @@ class OrderedDict(dict, MutableMapping):
# Those hard references disappear when a key is deleted from an OrderedDict.
def
__init__
(
self
,
*
args
,
**
kwds
):
'''Initialize an ordered dictionary. Signature is the same as for
regular dictionaries, but keyword arguments are not recommended
because their insertion order is arbitrary.
'''
if
len
(
args
)
>
1
:
raise
TypeError
(
'expected at most 1 arguments, got
%
d'
%
len
(
args
))
try
:
...
...
@@ -47,12 +52,14 @@ class OrderedDict(dict, MutableMapping):
self
.
update
(
*
args
,
**
kwds
)
def
clear
(
self
):
'od.clear() -> None. Remove all items from od.'
root
=
self
.
__root
root
.
prev
=
root
.
next
=
root
self
.
__map
.
clear
()
dict
.
clear
(
self
)
def
__setitem__
(
self
,
key
,
value
):
'od.__setitem__(i, y) <==> od[i]=y'
# Setting a new item creates a new link which goes at the end of the linked
# list, and the inherited dictionary is updated with the new key/value pair.
if
key
not
in
self
:
...
...
@@ -64,6 +71,7 @@ class OrderedDict(dict, MutableMapping):
dict
.
__setitem__
(
self
,
key
,
value
)
def
__delitem__
(
self
,
key
):
'od.__delitem__(y) <==> del od[y]'
# Deleting an existing item uses self.__map to find the link which is
# then removed by updating the links in the predecessor and successor nodes.
dict
.
__delitem__
(
self
,
key
)
...
...
@@ -72,6 +80,7 @@ class OrderedDict(dict, MutableMapping):
link
.
next
.
prev
=
link
.
prev
def
__iter__
(
self
):
'od.__iter__() <==> iter(od)'
# Traverse the linked list in order.
root
=
self
.
__root
curr
=
root
.
next
...
...
@@ -80,6 +89,7 @@ class OrderedDict(dict, MutableMapping):
curr
=
curr
.
next
def
__reversed__
(
self
):
'od.__iter__() <==> reversed(od)'
# Traverse the linked list in reverse order.
root
=
self
.
__root
curr
=
root
.
prev
...
...
@@ -88,6 +98,7 @@ class OrderedDict(dict, MutableMapping):
curr
=
curr
.
prev
def
__reduce__
(
self
):
'Return state information for pickling'
items
=
[[
k
,
self
[
k
]]
for
k
in
self
]
tmp
=
self
.
__map
,
self
.
__root
del
self
.
__map
,
self
.
__root
...
...
@@ -105,6 +116,10 @@ class OrderedDict(dict, MutableMapping):
items
=
MutableMapping
.
items
def
popitem
(
self
,
last
=
True
):
'''od.popitem() -> (k, v), return and remove a (key, value) pair.
Pairs are returned in LIFO order if last is true or FIFO order if false.
'''
if
not
self
:
raise
KeyError
(
'dictionary is empty'
)
key
=
next
(
reversed
(
self
))
if
last
else
next
(
iter
(
self
))
...
...
@@ -112,27 +127,41 @@ class OrderedDict(dict, MutableMapping):
return
key
,
value
def
__repr__
(
self
):
'od.__repr__() <==> repr(od)'
if
not
self
:
return
'
%
s()'
%
(
self
.
__class__
.
__name__
,)
return
'
%
s(
%
r)'
%
(
self
.
__class__
.
__name__
,
list
(
self
.
items
()))
def
copy
(
self
):
'od.copy() -> a shallow copy of od'
return
self
.
__class__
(
self
)
@classmethod
def
fromkeys
(
cls
,
iterable
,
value
=
None
):
'''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S
and values equal to v (which defaults to None).
'''
d
=
cls
()
for
key
in
iterable
:
d
[
key
]
=
value
return
d
def
__eq__
(
self
,
other
):
'''od.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive
while comparison to a regular mapping is order-insensitive.
'''
if
isinstance
(
other
,
OrderedDict
):
return
len
(
self
)
==
len
(
other
)
and
\
all
(
p
==
q
for
p
,
q
in
zip
(
self
.
items
(),
other
.
items
()))
return
dict
.
__eq__
(
self
,
other
)
def
__ne__
(
self
,
other
):
'''od.__ne__(y) <==> od!=y. Comparison to another OD is order-sensitive
while comparison to a regular mapping is order-insensitive.
'''
return
not
self
==
other
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment