More Collection Exercises
Collections (list
and dict
) are very important when working with data. Here are a few more exercises in case you need to grasp the concepts one more time.
Python Challenge
Loading
Python Challenge
Loading
Python Challenge
Loading
Python Challenge
Loading
Python Challenge
Loading
Python Challenge
Loading
Python Challenge
Loading
Python Challenge
Loading
Python Challenge
Loading
Python Challenge
Loading
Python Challenge
Loading
Python Challenge
Loading
Python Challenge
Loading
Slicing a List
Select SubsetIn Python, you can easily slice and retrieve a subset of a list
using the slice notation. The basic syntax is my_list[start:stop]
where my_list
is a list
-like value (or a variable). start
and stop
specify the index where you would like to start/stop retrieving values.
Slicing
my_list[start:stop]
retrieves all values fromstart
tostop - 1.
my_list[start:]
retrieves all values fromstart
to the end of the list.my_list[:stop]
retrieves all values from the beginning tostop - 1.
my_list[:]
retrieves all values from the list. This is often used to create a shallow copy of a list.
Python Challenge
Loading
Python Challenge
Loading
Python Challenge
Loading
Python Challenge
Loading
A string in Python is simply a
list
of characters.
Python Challenge
Loading
Python Challenge
Loading
Python Challenge
Loading
Python Challenge
Loading
Python Challenge
Loading
Python Challenge
Loading
Python Challenge
Loading
Python Challenge