Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
py-quickstart/docs/Iteration/for-loops/example-3.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
18 lines (15 sloc)
606 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Iterating iterables, examples using dictionaries and lists in python 3 | |
# example-3.py first example | |
list_of_fruit = ['apple', 'banana', 'cherry'] | |
for item in list_of_fruit: | |
print(item) | |
# example-3.py second example | |
dictionary = {'apple':3, 'banana':5, 'cherry':20} | |
for entry in dictionary.values(): # you can also use .items() or .keys() to get the dictionary pairs or keys | |
print(entry) | |
# example-3.py third example | |
dictionary = {'apple':3, 'banana':5, 'cherry':20} | |
for entry in dictionary.items(): # See!! | |
print(entry) | |
for entry in dictionary.keys(): | |
print(entry) |