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.
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'}}
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.
This can be completed a number of ways. Some things that may come in handy:
- The len() function (think for your incrementing primary key)
- for loops will come in handy, potentially more than once if you wish to make things easier.
- Splits for days. So many splits. (Remember, you can split on different characters to form lists of strings).
- Have fun, don't overthink it, if it gets complicated, try breaking things down into the smallest possible steps.