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
66d8b27c
Kaydet (Commit)
66d8b27c
authored
Eki 05, 2002
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Backport 1.160 on looping idioms. Excludes enumerate(), a Py2.3 feature.
üst
9efc1117
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
0 deletions
+29
-0
tut.tex
Doc/tut/tut.tex
+29
-0
No files found.
Doc/tut/tut.tex
Dosyayı görüntüle @
66d8b27c
...
...
@@ -2046,6 +2046,35 @@ pattern, list comprehensions can compactly specify the key-value list.
\end{verbatim}
\section
{
Looping Techniques
\label
{
loopidioms
}}
When looping through dictionaries, the key and corresponding value can
be retrieved at the same time using the
\method
{
items()
}
method.
\begin{verbatim}
>>> knights =
{
'gallahad': 'the pure', 'robin': 'the brave'
}
>>> for k, v in knights.items():
... print k, v
...
gallahad the pure
robin the brave
\end{verbatim}
To loop over two or more sequences at the same time, the entries
can be paired with the
\function
{
zip()
}
function.
\begin{verbatim}
>>> questions = ['name', 'quest', 'favorite color']
>>> answers = ['lancelot', 'the holy grail', 'blue']
>>> for q, a in zip(questions, answers):
... print 'What is your
%s? It is %s.' % (q, a)
...
What is your name? It is lancelot.
What is your quest? It is the holy grail.
What is your favorite color? It is blue.
\end{verbatim}
\section
{
More on Conditions
\label
{
conditions
}}
The conditions used in
\code
{
while
}
and
\code
{
if
}
statements above can
...
...
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