Skip to content

Instantly share code, notes, and snippets.

@derekm1215
Last active September 3, 2020 15:16
Show Gist options
  • Save derekm1215/e7cdb9b7d462382e503138f143f71795 to your computer and use it in GitHub Desktop.
Save derekm1215/e7cdb9b7d462382e503138f143f71795 to your computer and use it in GitHub Desktop.

User Database Problem

You have been tasked with populating a lead database with information about people scraped from a social media website. The social media website includes a bio of the user on the user's profile page that looks like this:

"Derek's age is 35 and lives in Chicago".

The data will be provided in CSV (Comma Separated Values) format with each "value" being the entire sentence separated by a comma.

Your goal is to extract the name, age, and city and insert it into a dictionary using incrementing numbers as the "primary key". The primary key is used to ensure that each value has a unique identifier since the chance that someone's first name, city, and age matching someone else's is very high. This will ensure those entries in the database are unique.

End Result

Derek's age is 35 and lives in chicago.,Lydia's age is 34 and lives in chicago.,Matt's age is 33 and lives in LA

will look like:

{1: {'age': 35, 'city': 'chicago', 'name': 'Derek'},
 2: {'age': 34, 'city': 'chicago', 'name': 'Lydia'},
 3: {'age': 33, 'city': 'LA', 'name': 'Matt'}}

Ensure you remove any punctuation from the dictionary!

The Sentences

Derek's age is 35 and lives in chicago.,Lydia's age is 34 and lives in chicago.,Matt's age is 33 and lives in LA.,Allie's age is 27 and lives in NYC.,Ang's age is 19 and lives in SF.

Good Luck!

Hints:

This can be completed a number of ways. Some things that may come in handy:

  1. The len() function (think for your incrementing primary key)
  2. for loops will come in handy, potentially more than once if you wish to make things easier.
  3. Splits for days. So many splits. (Remember, you can split on different characters to form lists of strings).
  4. Have fun, don't overthink it, if it gets complicated, try breaking things down into the smallest possible steps.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment