We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,376 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

delete an item in a list which is in a dictionary

inventory = {'gold' : 500,
'pouch' : ['flint', 'twine', 'gemstone'],
'backpack' : ['xylophone','dagger', 'bedroll','bread loaf']}

how do i delete the item 'dagger' only from the 'backpack'

2
Contributors
1
Reply
6 Minutes
Discussion Span
3 Months Ago
Last Updated
2
Views
ITech
Light Poster
39 posts since Jun 2007
Reputation Points: 11
Solved Threads: 0
Skill Endorsements: 0

This might help you:

try:
    inventory.get('backpack').remove('dagger')
except ValueError:
    pass
Lucaci Andrew
Practically a Master Poster
649 posts since Jan 2012
Reputation Points: 91
Solved Threads: 91
Skill Endorsements: 12

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0588 seconds using 2.66MB