Python Forum
Trouble displaying items from lists
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble displaying items from lists
#9
(May-18-2017, 07:37 AM)Liquid_Ocelot Wrote:
Quote:Incidentally, keeping "parallel arrays" like this is a well-known anti-pattern (you problem above is exactly one of the frequent pitfalls) and you should really be using a single array of "aggregates" that contain the Nickname, Name, and other information for each person in the address book.


Do you happen to have any reference material that explains how to perform this?  My task outline states I need to use a dictionary and what I've done is just convert the lists (Names,nicknames,Numbers,address) into the one dictionary (not sure if that is even correct in the code either xD)

I don't see any useful dictionary in your code. I would expect a dictionary where nicknames are the keys, and the values are tuples with name, address, and phone number. In other words, your code should have something like:

# Add the person:
persons[nickname]=(name,address,phone)

# Search the person:
if nickname in persons:
    name,address,phone=persons[nickname]
    print nickname, name, address, phone
else:
   print "Not found"
Look ma, no arrays!
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply


Messages In This Thread
RE: Trouble displaying items from lists - by Ofnuts - May-18-2017, 06:06 AM
RE: Trouble displaying items from lists - by Ofnuts - May-18-2017, 01:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  QUERY on Looping and creating lists as items within dictionaries ajayachander 3 2,354 Mar-26-2020, 02:03 PM
Last Post: ajayachander
  Trouble in lists erfanakbari1 2 2,333 Feb-26-2019, 08:46 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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