Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Don't excute my code
#8
There are three ways to loop over a dictionary. Say we have this dictionary:

knights = {'Lancelot': 'Blue', 'Robin': "I don't know that", 'Galahad': 'Blue, no green', 'Arthur': 'What do you mean?'}
If we do a plain loop over the dictionary (for name in knights:) we get the keys: Lancelot; Robin; Galahad; and Arthur. We can also loop over the values (for answer in knights.values():) and get Blue; I don't know that; Blue, no green; and What do you mean? We can also loop over both with items (for name, answer in knights.values():) and get the pairs (Lancelot, Blue); (Robin, I don't know that); and so on.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Don't excute my code - by RavCOder - Sep-30-2019, 10:31 AM
RE: Don't excute my code - by buran - Sep-30-2019, 10:38 AM
RE: Don't excute my code - by RavCOder - Sep-30-2019, 12:49 PM
RE: Don't excute my code - by jefsummers - Sep-30-2019, 02:13 PM
RE: Don't excute my code - by ichabod801 - Oct-01-2019, 12:34 PM
RE: Don't excute my code - by RavCOder - Oct-01-2019, 12:48 PM
RE: Don't excute my code - by ichabod801 - Oct-01-2019, 01:21 PM
RE: Don't excute my code - by jefsummers - Oct-01-2019, 01:48 PM
RE: Don't excute my code - by buran - Oct-01-2019, 02:10 PM
RE: Don't excute my code - by ichabod801 - Oct-01-2019, 02:34 PM
RE: Don't excute my code - by RavCOder - Oct-01-2019, 02:40 PM
RE: Don't excute my code - by RavCOder - Oct-01-2019, 03:45 PM
RE: Don't excute my code - by ichabod801 - Oct-01-2019, 03:51 PM
RE: Don't excute my code - by RavCOder - Oct-01-2019, 03:56 PM
RE: Don't excute my code - by jefsummers - Oct-01-2019, 04:22 PM
RE: Don't excute my code - by RavCOder - Oct-02-2019, 10:21 AM
Problem with dictionary - by RavCOder - Oct-01-2019, 07:58 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020