User Tools

Site Tools


it:how-to_iterate_in_python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

it:how-to_iterate_in_python [2018/12/01 19:38] (current)
pmay created
Line 1: Line 1:
 +====== How-To Iterate in Python ======
  
 +===== Iterate a Dictionary =====
 +Iterate keys only:
 +<code python>
 +d = {'​x':​ 1, '​y':​ 2, '​z':​ 3} 
 +for key in d:
 +    print(key, '​corresponds to', d[key])
 +</​code>​
 +
 +Iterate keys and values:
 +<code python>
 +d = {'​x':​ 1, '​y':​ 2, '​z':​ 3} 
 +for key, value in d.items():
 +    print(key, '​corresponds to', value)
 +</​code>​
it/how-to_iterate_in_python.txt · Last modified: 2018/12/01 19:38 by pmay