Code Monkey home page Code Monkey logo

itp-u3-c2-football-dictionaries's Introduction

Football Dictionaries

Today's project will deal with two of our greatest passions: dictionaries and football ๐Ÿ˜‰. This project requires the use of nested collections (lists of lists, dicts nested under lists, etc) and nested control flow structures. It's the final challenge regarding collections for our course. If you can complete this project, you'll become a Master of Data and Collections and you might even get a gold star.

Warm up

Before approaching the main tasks of the project, there's a warm up section to revisit topics about collections (especially when they're nested). Open the notebook Warm Up Activities.ipynb to practice with them. There's also a notebook containing the solutions in case you need some help.

The Real Project

After finishing the warm up section, you'll be ready to take on the real project. This project is divided into 3 assignments, each one requires something different. But all these assignments will deal with the same initial data: a list of players structured as a "list of lists".

Translation to human: There's a big list that has players inside. But each player is represented as a list, with each position in the list being a different piece of information for the player.

Note: This project is very similar to the one we did organizing the invoice data on class 1 of this week!

Example:

SQUADS_DATA = [
  [
    "1",                                     # Number
    "GK",                                    # Position
    "Juan Botasso",                          # Name
    "(1908-10-23)23 October 1908 (aged 21)", # Date of Birth
    "",                                      # Caps
    "Quilmes",                               # Club
    "Argentina",                             # Country (Players Country)
    "Argentina",                             # Club Country
    "1930"                                   # Year
  ],
  [
    "9",
    "FW",
    "Roberto Cherro",
    "(1907-02-23)23 February 1907 (aged 23)",
    "",
    "Boca Juniors",
    "Argentina",
    "Argentina",
    "1930"
  ]
  # More Players...
]

Your job through this entire group project will be to transform these lists to Dictionaries.

Assignment 1 - Lists to Dicts

The first assignment just requires you to turn these players into dictionaries with the following structure:

{
    'number': ...,
    'position': ...,
    'name': ...,
    'date_of_birth': ...,
    'caps': ...,
    'club': ...,
    'country': ...,
    'club_country': ...,
    'year': ...,
}

Given our previous example, now our new list containing players as dictionaries would look like:

SQUADS_DATA = [
  {
    'number': "1",
    'position': "GK",
    'name': "Juan Botasso",
    'date_of_birth': "(1908-10-23)23 October 1908 (aged 21)",
    'caps': "",
    'club': "Quilmes",
    'country': "Argentina",
    'club_country': "Argentina",
    'year': "1930"
  },
  {
    'number': "9",
    'position': "FW",
    'name': "Roberto Cherro",
    'date_of_birth': "(1907-02-23)23 February 1907 (aged 23)",
    'caps': "",
    'club': "Boca Juniors",
    'country': "Argentina",
    'club_country': "Argentina",
    'year': "1930"
  }
  # More Players...
]

Assignment 2

This assignment is similar to the previous one, but instead of having just one big list with all the players, we're going to group them by position. Your result will look something like:

# Please note we're returning a dictionary instead of a list
{
  "GK": [{..player1..}, {..player2..}],
  "DF": [{..player1..}, {..player2..}],
  "MF": [{..player1..}, {..player2..}],
  "FW": [{..player1..}, {..player2..}],
}

Assignment 3

And finally this is really similar to the second assignment but we'll add one more level of nesting. This function will return the players grouped by country, and per each country, grouped by position. Example:

{
  "Argentina": {
    "GK": [{..player1..}, {..player2..}],
    "DF": [{..player1..}, {..player2..}],
    "MF": [{..player1..}, {..player2..}],
    "FW": [{..player1..}, {..player2..}],
  },
  "Brazil": {
    "GK": [{..player1..}, {..player2..}],
    "DF": [{..player1..}, {..player2..}],
    "MF": [{..player1..}, {..player2..}],
    "FW": [{..player1..}, {..player2..}],
  }
}

Walkthrough solution

We've got together with a few students to present a possible solution. Watch it on YouTube:

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.