jimbo's People
jimbo's Issues
CHALLENGE: Know your types
Fill in the blanks with the correct data type names:
1234
____1234.56
____"1234.56"
____True
____["I am", "a silly" "goose"]
____{"beans": "franks", "billy": "club"}
____(100, 200, 300, 400)
____
CHALLENGE: Make me a list and a dictionary of dog breeds
- - List of dog breed names
- - Dict of dog breed names (keys) and what they were bred for (values)
As a reminder, here is a single dog breed. Note that the key name
and bred_for
are only 1 level deep. No need to go into nested dictionaries.
Here is the URL for the data: https://api.thedogapi.com/v1/breeds
{
"weight": {
"imperial": "6 - 13",
"metric": "3 - 6"
},
"height": {
"imperial": "9 - 11.5",
"metric": "23 - 29"
},
"id": 1,
"name": "Affenpinscher",
"bred_for": "Small rodent hunting, lapdog",
"breed_group": "Toy",
"life_span": "10 - 12 years",
"temperament": "Stubborn, Curious, Playful, Adventurous, Active, Fun-loving",
"origin": "Germany, France",
"reference_image_id": "BJa4kxc4X",
"image": {
"id": "BJa4kxc4X",
"width": 1600,
"height": 1199,
"url": "https://cdn2.thedogapi.com/images/BJa4kxc4X.jpg"
}
},
Use the requests
module to get the data into python:
import requests
url = "https://api.thedogapi.com/v1/breeds"
data = requests.get(url).json()
# loop through the results:
for item in data:
print(item.get("name"), item.get("bred_for")
CHALLENGE: Print dog breed information
- Print each dog breed name and what they were bred for
Here is an example of a dog breed:
{
"weight": {
"imperial": "6 - 13",
"metric": "3 - 6"
},
"height": {
"imperial": "9 - 11.5",
"metric": "23 - 29"
},
"id": 1,
"name": "Affenpinscher",
"bred_for": "Small rodent hunting, lapdog",
"breed_group": "Toy",
"life_span": "10 - 12 years",
"temperament": "Stubborn, Curious, Playful, Adventurous, Active, Fun-loving",
"origin": "Germany, France",
"reference_image_id": "BJa4kxc4X",
"image": {
"id": "BJa4kxc4X",
"width": 1600,
"height": 1199,
"url": "https://cdn2.thedogapi.com/images/BJa4kxc4X.jpg"
}
},
Use the requests module to get the data. You can access the values by the accessor item["key"]
or by using the get
function that every dictionary has. For example:
my_dict = {"name": "Joe Mama", "age": 66}
# accessor
my_dict["name"]
>>> Joe Mama
# or
my_dict.get("name")
>>> Joe Mama
Here's some starter code:
import requests
url = "https://api.thedogapi.com/v1/breeds"
data = requests.get(url).json()
# loop through each item and print the name and bred_for value
for item in data:
print(.......)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.