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
3f2b1849
Kaydet (Commit)
3f2b1849
authored
Nis 24, 2011
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Other minor clean-ups.
üst
c646743d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
8 deletions
+15
-8
collections.py
Lib/collections.py
+15
-8
No files found.
Lib/collections.py
Dosyayı görüntüle @
3f2b1849
...
@@ -35,9 +35,9 @@ class OrderedDict(dict):
...
@@ -35,9 +35,9 @@ class OrderedDict(dict):
# Each link is stored as a list of length three: [PREV, NEXT, KEY].
# Each link is stored as a list of length three: [PREV, NEXT, KEY].
def
__init__
(
self
,
*
args
,
**
kwds
):
def
__init__
(
self
,
*
args
,
**
kwds
):
'''Initialize an ordered dictionary.
Signature is the same as for
'''Initialize an ordered dictionary.
The signature is the same as
regular dictionaries, but keyword arguments are not recommended
regular dictionaries, but keyword arguments are not recommended
because
because
their insertion order is arbitrary.
their insertion order is arbitrary.
'''
'''
if
len
(
args
)
>
1
:
if
len
(
args
)
>
1
:
...
@@ -69,18 +69,20 @@ class OrderedDict(dict):
...
@@ -69,18 +69,20 @@ class OrderedDict(dict):
link_prev
[
NEXT
]
=
link_next
link_prev
[
NEXT
]
=
link_next
link_next
[
PREV
]
=
link_prev
link_next
[
PREV
]
=
link_prev
def
__iter__
(
self
,
NEXT
=
1
,
KEY
=
2
):
def
__iter__
(
self
):
'od.__iter__() <==> iter(od)'
'od.__iter__() <==> iter(od)'
# Traverse the linked list in order.
# Traverse the linked list in order.
NEXT
,
KEY
=
1
,
2
root
=
self
.
__root
root
=
self
.
__root
curr
=
root
[
NEXT
]
curr
=
root
[
NEXT
]
while
curr
is
not
root
:
while
curr
is
not
root
:
yield
curr
[
KEY
]
yield
curr
[
KEY
]
curr
=
curr
[
NEXT
]
curr
=
curr
[
NEXT
]
def
__reversed__
(
self
,
PREV
=
0
,
KEY
=
2
):
def
__reversed__
(
self
):
'od.__reversed__() <==> reversed(od)'
'od.__reversed__() <==> reversed(od)'
# Traverse the linked list in reverse order.
# Traverse the linked list in reverse order.
PREV
,
KEY
=
0
,
2
root
=
self
.
__root
root
=
self
.
__root
curr
=
root
[
PREV
]
curr
=
root
[
PREV
]
while
curr
is
not
root
:
while
curr
is
not
root
:
...
@@ -120,7 +122,7 @@ class OrderedDict(dict):
...
@@ -120,7 +122,7 @@ class OrderedDict(dict):
yield
self
[
k
]
yield
self
[
k
]
def
iteritems
(
self
):
def
iteritems
(
self
):
'od.iteritems -> an iterator over the (key, value)
item
s in od'
'od.iteritems -> an iterator over the (key, value)
pair
s in od'
for
k
in
self
:
for
k
in
self
:
yield
(
k
,
self
[
k
])
yield
(
k
,
self
[
k
])
...
@@ -131,6 +133,11 @@ class OrderedDict(dict):
...
@@ -131,6 +133,11 @@ class OrderedDict(dict):
__marker
=
object
()
__marker
=
object
()
def
pop
(
self
,
key
,
default
=
__marker
):
def
pop
(
self
,
key
,
default
=
__marker
):
'''od.pop(k[,d]) -> v, remove specified key and return the corresponding
value. If key is not found, d is returned if given, otherwise KeyError
is raised.
'''
if
key
in
self
:
if
key
in
self
:
result
=
self
[
key
]
result
=
self
[
key
]
del
self
[
key
]
del
self
[
key
]
...
@@ -186,8 +193,8 @@ class OrderedDict(dict):
...
@@ -186,8 +193,8 @@ class OrderedDict(dict):
@classmethod
@classmethod
def
fromkeys
(
cls
,
iterable
,
value
=
None
):
def
fromkeys
(
cls
,
iterable
,
value
=
None
):
'''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S
'''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S
.
and values equal to v (which defaults to None)
.
If not specified, the value defaults to None
.
'''
'''
self
=
cls
()
self
=
cls
()
...
...
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