Python Forum
Not understanding dictionaries
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not understanding dictionaries
#1
Ok, I am reading a book automate the boring stuff, I am on the dictionaries chapter because I’m focusing on dictionaries right now maybe I should go back to for loops but,
I have a couple questions. Regarding the following code and what it is doing.
At the for loop for k,v in inventory.items() what is happening here?
At print(str(v) + ‘’ + k ) what is the ‘ ‘ empty string?
And I guess at item_total += v what is going on here as well?





stuff={
	'rope':1,'torch':6,'gold coins':45,'dagger':1,'arrow':12
}

def display_Inventory(Inventory):
	print('Inventory')
	Item_total=0
	for k,v in Inventory.items():
		print(str(v)+''+k)
		Item_total += v
		print('Total number of items:' + str(Item_total))
		
display_Inventory(stuff)
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,243 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