Python Dictionaries

  • Comments posted to this topic are about the item Python Dictionaries

  • Nice one, thanks Steve
    Definitely time to dust off those old Python skills

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    “libera tute vulgaris ex”

  • Hmm good question Steve, time to learn a bit of Python me thinks.

    ...

  • Easy one for me. Here is something cool to think about how list and dicts can work together.


    # Two dictionaries with two sets of rows and columns
    dictA = {'CustomerID': [1, 2, 3, 4, 5],  'FirstName': ['John', 'Joe', 'Sarah', 'Jane', 'Sam']}
    dictB = {'CustomerID': [1, 2, 3, 4, 5],  'FirstName': ['Sue', 'Aiden', 'Stephanie', 'Steve', 'Faye']}

    # List of my dictionaries
    myList = [dictA, dictB]

    # Being our dictionaries contain the same field names, we can use a list to help us keep track of each dict and iterate over them.
    # We can then use a forloop to iterate and list out each list within each dict.
    for records in myList:
         for customers in records['FirstName']:
              print customers

    Course, you could just combine the dicts too. But it's interesting to think about how they can be separate and reference each other too.

  • I've never used python, so I guessed.  I guessed poorly.

  • Ed Wagner - Friday, November 3, 2017 11:16 AM

    I've never used python, so I guessed.  I guessed poorly.

    I've never used it either,  but I have read odd bits of python code here and there (helping someone find his silly errors) and had a vague memory of hash tables being called dictionaries and using square brackets for keys.
    My son tells me I should learn the language, but I'm not convinced.

    Tom

  • Nice question.  Thanks Steve.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply