2.1. Exercises

Name that Data Structure

Data Structure True and False

Coding questions

Instructions:
Running a coding exercise for the first time could take a bit of time for everything to load. Be patient, it could take a few minutes.

When you see ____ in a coding exercise, replace it with what you assume to be the correct code. Run it and see if you obtain the desired output. Submit your code to validate if you were correct.

Make sure you remove the hash (#) symbol in the coding portions of this question. We have commented them so that the line won’t execute and you can test your code after each step.

The Data Structure Basics

Let’s explore how to add to a list, slice it and convert it into a tuple.

Tasks:

  • Using the list provided, add a pen, a scrap paper, a 7.3 and a True element.
  • Find the length of the list after adding the element and save the value in an object named drawer_length.
  • Slice the list from 4 to scrap paper and save this in an object named cleaned_junk_drawer.
  • Finally, convert it into a set and name it junk_set.
Hint 1
  • The verbs .append() and len() may be handy.
  • You can convert your list to a tuple with `tuple().
  • Have you sliced keeping in mind the end of the slice is excluded?
Fully worked solution:


Making a Dataframe from Lists

Let’s use lists and convert them into a pandas dataframe.

Tasks:

  • Use the lists given in the cell below to make a dataframe.
  • Name the dataframe family.
Hint 1
  • Are you using pd.DataFrame()?
  • Are you using the arguments data and columns?
Fully worked solution: