Practice Python Lists basics
Practice Python Lists basics Data Science Project
Python Collections

Practice Python Lists basics

Learn the basics of Python lists. You will learn appending, concatenating, indexing, slicing, and iterating through lists. Also, you will learn how to check the length of a list, and how to check if an element is in a list.
Start this project
Practice Python Lists basicsPractice Python Lists basics
Project Created by

Santiago Basulto

Project Activities

All our Data Science projects include bite-sized activities to test your knowledge and practice in an environment with constant feedback.

All our activities include solutions with explanations on how they work and why we chose them.

codevalidated

Append `'world'` to list

The variable l contains a simple list with 3 elements. Append the string "world" to the end of the list l.

codevalidated

Concatenate the two lists

Concatenate the two lists l1 and l2 and store the results in the list concat_result.

Important! l1 and l2 should NOT be modified. This should be an immutable operation, only concat_result should be affected.

codevalidated

Concatenate, shortest first

Define the function concatenate_shortest_first that receives two lists, l1 and l2 and returns the lists concatenated, BUT, the trick is that the SHORTEST list should be the first one appearing in the resulting list.

input

How many words does the variable `words` contain?

The variable words contains a list of words. How many words does it contain?

input

What's the 500th word in the `words` list?

Can you find the 500th word? Enter it below and check.

codevalidated

Select the sublist containing the words from position 100th to 150th

Select the sublist containing the words from the position 100th to 150th in the variable words_100_to_150.

Important! Both the 100th and 150th words should be included in the sublist. Also, remember that lists are 0-indexed.

codevalidated

Select the sublist containing the last 50 words

Select the sublist of words containing the last 50 elements. Store your result in the variable last_50_words.

multiplechoice

Check the words that are part of the `words` list

Check only the words that are part of the words list. If the word is not included in the list, don't check it.

input

How many words finish with the character `x`?

Use iteration to count how many words finish with the character x.

codevalidated

Find all the words that have the substring `cc` in them

Use iteration to create a sublist of all the words that contain the substring cc in them (example, bocci, yucca) and store them in the variable words_with_cc.

codevalidated

Find all the words that start and end with an `y`

Use iteration to create a sublist of all the words that both start and end with the character y (example, yobby, yummy). Store your results in the variable words_with_y.

codevalidated

Find the words that contain the characters `s`, `m` and `b` in order of occurrence

Nerd moment of the day...

In 1992, Andrew Tridgell was decided on creating an open source re-implementation of the privative SMB networking protocol for Linux/Unix. He developed the first version in just a few weeks, but once he was ready to publish it, he needed a name for it.

To come up with the name, he found a list of all the words that contained the characters S, M, and B in them, in that particular order. That's how [Samba](https://en.wikipedia.org/wiki/Samba_(software%29) was born. The word samba has the characters s, m and b in order.

Your task is to replicate Andrew's results by creating a sublist of all the words in words that have s, m and b in that order. Store your results in the variable samba_words.

input

How many words contain the substring `zaz`?

In this activity, you will use iteration on the list words to count how many words contain the substring zaz in them.

codevalidated

Find all the words in an even position

Let's define the position of a word in words starting in 1st, 2nd, etc. For example, here are the first 10 words in words:

   1st      2nd      3rd      4th     5th ...                              9th      10th
['jetty', 'wizzo', 'cuppa', 'cohoe', 'gurks', 'squad', 'beisa', 'shrug', 'fossa', 'fluyt']

Your job is to create a sublist containing words only in positions numerically "even", that is, positions 2, 4, 6, etc.

Store your results in the variable even_positioned_words.

Your expected results are:

['wizzo', 'cohoe', 'squad', 'shrug', ...]
codevalidated

Iterate the list in reverse order, and find all the words that start with `s` and end with `y`

So far, you've created sublists by just iterating words as it is. For this task, you need to create the sublist words_s_y_reversed containing words that start with s and end with y, but the order has to be reversed.

Example, in words you can find:

[jetty, ..., seepy, ..., seely, ..., stary]

Your sublist should contain:

>>> words_s_y_reversed
[stary, seely, seepy, ...]
Practice Python Lists basicsPractice Python Lists basics
Project Created by

Santiago Basulto

This project is part of

Python Collections

Explore other projects