Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionary python program
#8
needs indentation, this code does not modify the dictionary, only the value after retreving
for key in sales.keys():
    print(sales[key] + 1)
A better way:
>>> for key, value in sales.items():
...     print('Item: {:10s} sales: {:6d}'.format(key, value))
... 
Item: beef       sales:      4
Item: catfish    sales:      8
Item: alfredo    sales:     12
Item: peppers    sales:     18
>>>
Reply


Messages In This Thread
Dictionary python program - by NLittle17 - Jan-05-2019, 03:04 PM
RE: Dictionary python program - by Larz60+ - Jan-05-2019, 03:06 PM
RE: Dictionary python program - by NLittle17 - Jan-05-2019, 03:07 PM
RE: Dictionary python program - by Larz60+ - Jan-05-2019, 03:24 PM
RE: Dictionary python program - by NLittle17 - Jan-05-2019, 03:32 PM
RE: Dictionary python program - by Larz60+ - Jan-05-2019, 05:53 PM
RE: Dictionary python program - by NLittle17 - Jan-05-2019, 07:31 PM
RE: Dictionary python program - by Larz60+ - Jan-06-2019, 04:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Running the Regressive Imagery Dictionary program... treegreen 3 2,792 May-02-2019, 10:45 PM
Last Post: treegreen
  Convert List of Dictionary to dictionary of dictionary list in python kk230689 2 58,654 Apr-27-2019, 03:13 AM
Last Post: perfringo
  creating a username and pword program using a #def statement and #dictionary zcode12 3 3,216 Oct-14-2018, 04:41 AM
Last Post: volcano63

Forum Jump:

User Panel Messages

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