Sequences 2 - Challenges

Download exercises zip

Browse online files

Challenge - ppulsar

Given a list of words universe, output a list which has first letters capitalized, double ‘p’s converted into a single one, and ‘The’ added at the beginning of each word

  • USE list comprehension in one line of code

IN: universe = ['star','space','nebula','proton','pproppulsion','black hole','ppulsar']

OUT: ['The Star', 'The Space', 'The Nebula', 'The Proton', 'The Propulsion', 'The Black hole', 'The Pulsar']

Challenge - broken wisdom

Given a list of words, produce a list of tuples of characters, with half the characters of each word.

  • USE list comprehension in one line of code

  • BEWARE of odd length words

IN: ['concepts','broken','wisdom','reality','unbroken','philosophy']

OUT: [('c', 'o', 'n', 'c'), ('b', 'r', 'o'), ('w', 'i', 's'), ('r', 'e', 'a'), ('u', 'n', 'b', 'r'), ('p', 'h', 'i', 'l', 'o')]

[2]:


meditation = ['concepts','broken','wisdom','reality','unbroken','philosophy'] # write here

Challenge - rupture

Given a list of words rupture either lowercase or uppercase, and a list of words gather either uppercase or lowercase, collect only those words from rupture and separated the characters with dashes -

  • USE list comprehension in one line of code

IN:

gather = `['TREMOR', 'hypocenter','DANGER', 'seismic']`
rupture = ['earthquake','tremor', 'temblor','litosphere', 'danger', 'TREMOR',
           'hypocenter', 'seismic','waves', 'LANDSLIDES', 'SEISMIC']

OUT: ['t-r-e-m-o-r','d-a-n-g-e-r', 't-r-e-m-o-r', 'h-y-p-o-c-e-n-t-e-r', 's-e-i-s-m-i-c', 's-e-i-s-m-i-c']

[3]:


gather = ['TREMOR', 'hypocenter','DANGER', 'seismic'] rupture = ['earthquake','tremor', 'temblor','litosphere', 'danger', 'TREMOR', 'hypocenter', 'seismic','waves', 'LANDSLIDES', 'SEISMIC'] # write here

Challenge - cyclone

Given a list of words, outputs a list of tuples coupling a word position with the word itself

  • USE list comprehension in one line of code

  • DO NOT use search methods (no .index, .find, …)

IN: ['rotating', 'storm', 'pressure', 'tropical', 'typhoon', 'strong winds', 'severe']

OUT:

[(0, 'rotating'), (1, 'storm'),   (2, 'pressure'),     (3, 'tropical'), (4, 'pressure'),
 (5, 'typhoon'),  (6, 'typhoon'), (7, 'strong winds'), (8, 'severe'),   (9, 'typhoon')]
[4]:

cyclone = ['rotating', 'storm', 'pressure', 'tropical', 'pressure','typhoon','typhoon', 'strong winds', 'severe', 'typhoon'] # write here