Python Forum
Thread Rating:
  • 2 Vote(s) - 1.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List logic
#6
(Apr-22-2017, 10:50 AM)ichabod801 Wrote: I'm not sure what you need, you've got it all right there. Your paragraph starting with "I know it's going to..." is exactly what I would tell you to do.

There are list and dictionary tutorials in the tutorials sub-forum of this site. I'm sure that you could web search on "python list tutorial" and find more.

Yeah, I guess I should change the subject of the thread to list comprehension lol. I know the logic behind it but I do not know how to write it... :(

I have another question as well pertaining to dicts / lists...

say I have a Inventory lists such as:

stuff = {'rope' : 1, 'torch' : 6, 'gold coin' : 42, 'dagger' : 1, 'arrow' : 12}

def displayInventory(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))
displayInventory(stuff)
and I want to add a list of loot to the inventory dict... the list of loot being:

def addToInventory(inventory, addedItems):
    # code to add dragonLoot to inventory goes here
    
dragonLoot = ['gold coin', 'dagger', 'gold coin', 'ruby']
how would I go about doing so?
Reply


Messages In This Thread
List logic - by Low_Ki_ - Apr-22-2017, 02:03 AM
RE: List logic - by Low_Ki_ - Apr-22-2017, 03:08 AM
RE: List logic - by ichabod801 - Apr-22-2017, 10:50 AM
RE: List logic - by Low_Ki_ - Apr-22-2017, 04:56 PM
RE: List logic - by idontreallywolf - Apr-22-2017, 11:10 AM
RE: List logic - by tomhath - Apr-22-2017, 03:41 PM
RE: List logic - by ichabod801 - Apr-22-2017, 05:44 PM
RE: List logic - by Low_Ki_ - Apr-22-2017, 06:53 PM
RE: List logic - by ichabod801 - Apr-22-2017, 09:24 PM
RE: List logic - by Low_Ki_ - Apr-22-2017, 11:46 PM
RE: List logic - by Low_Ki_ - Apr-23-2017, 02:29 AM
RE: List logic - by wavic - Apr-23-2017, 04:21 AM
RE: List logic - by Low_Ki_ - Apr-23-2017, 04:31 AM

Forum Jump:

User Panel Messages

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