Python Forum
Not understanding dictionaries
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not understanding dictionaries
#3
items() returns all of the keys/values in the dictionary, one tuple at a time. So each time through the loop, k is set to one of the keys, and v to the corresponding value of that key.

>>> d = {'key': 'value', 'A': 1, 'B': 2}
>>> list(d.items())
[('key', 'value'), ('A', 1), ('B', 2)]
The empty string is probably a typo. I'd guess someone wanted a blank space between the key and the value in the print and it became empty instead of a space.

This is the form of an augmented assignment. It's basically the same thing as writing Item_total = Item_total + v
Reply


Messages In This Thread
Not understanding dictionaries - by gr3yali3n - Jun-18-2020, 08:22 PM
RE: Not understanding dictionaries - by Larz60+ - Jun-18-2020, 08:56 PM
RE: Not understanding dictionaries - by bowlofred - Jun-18-2020, 08:56 PM
RE: Not understanding dictionaries - by gr3yali3n - Jun-20-2020, 03:10 AM
RE: Not understanding dictionaries - by buran - Jun-20-2020, 03:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help in understanding scope of dictionaries and lists passed to recursive functions barles 2 3,326 Aug-11-2018, 06:45 PM
Last Post: barles

Forum Jump:

User Panel Messages

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