😺
wiki
  • Welcome, Internet Strangers!
  • sql
    • etl
      • Basics to Remember
      • Context to Remember
      • Naming Practices
      • ETL Steps
    • performance
      • Please No
      • Initial Explorations
      • Stored Procedures
    • select-tricks
      • Over Partition
      • Stored Procedures*
      • Creating Parameters
  • python
    • Working with Files
    • Classes in Python
    • Dictionaries
    • Working with Strings
    • Using Lambda
    • Seaborn
    • machine-learning
      • Learning Pandas
      • MatPlotLib! The Dreaded Line Graph...
      • matlab-qualgraphs-notes
      • Linear Regression Example
      • kNN Analysis in ScikitLearn
    • Neat Snippets
  • bash
    • helpful_cmd
  • math
    • Basic Definitions
    • Linear Regressions
    • Meaningful Sampling
Powered by GitBook
On this page

Was this helpful?

  1. python

Dictionaries

Basic way to zip together two lists into a dictionary:

songs = ["Like a Rolling Stone", "Satisfaction", "Imagine", "What's Going On", "Respect", "Good Vibrations"]
playcounts = [78, 29, 44, 21, 89, 5]

plays = {key:value for key, value in zip(songs, playcounts)}

Looping through a dictionary:

pct_women_in_occupation = {"CEO": 28, "Engineering Manager": 9, "Pharmacist": 58, "Physician": 40, "Lawyer": 37, "Aerospace Engineer": 9}

for job, value in pct_women_in_occupation.items():
  print("Women make up {} percent of {}s".format(value, job))

Also, you can call all keys with dict.keys() and all values with dict.values()

PreviousClasses in PythonNextWorking with Strings

Last updated 3 years ago

Was this helpful?