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.
The variable l
contains a simple list with 3 elements. Append the string "world"
to the end of the list l
.
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.
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.
The variable words
contains a list of words. How many words does it contain?
Can you find the 500th word? Enter it below and check.
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.
Select the sublist of words
containing the last 50 elements. Store your result in the variable last_50_words
.
Check only the words that are part of the words
list. If the word is not included in the list, don't check it.
Use iteration to count how many words finish with the character x
.
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
.
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
.
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
.
In this activity, you will use iteration on the list words
to count how many words contain the substring zaz
in them.
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', ...]
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, ...]