GithubHelp home page GithubHelp logo

jimbo's People

Contributors

kgalliher avatar mezmer1 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

jimbo's Issues

CHALLENGE: Make me a list and a dictionary of dog breeds

  1. - List of dog breed names
  2. - 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(.......)

CHALLENGE: Know your types

Fill in the blanks with the correct data type names:

  1. 1234 ____
  2. 1234.56 ____
  3. "1234.56" ____
  4. True ____
  5. ["I am", "a silly" "goose"] ____
  6. {"beans": "franks", "billy": "club"} ____
  7. (100, 200, 300, 400) ____

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.