#python #listcomprehension #advanced
In this video we will cover some python challenges, and how to solve them. However these challenges are made to test you, and help build your skills so please try to solve them before watching this video!
Hope this helps solidify your knowledge on list comprehension, and hope you enjoy the video!
Twitter: / bitwizard8
Discord: / discord
Rules:
1: Each challenge must be a function
2: Must you list/dictionary comprehension
3: Output must match as shown
Challenge 1:
Given a list of numbers, write a list comprehension that produces a list of each number doubled.
numbers=[1, 2, 3, 4, 5]
Challenge 2:
Given a list of numbers, write a list comprehension that produces a list of the squares of each number.
numbers=[-1, 4, 9, 11]
Challenge 3:
Given a list of numbers, write a list comprehension that produces a list of only the even numbers in that
list.
numbers=[-4, 0, 3, 6, 7, 9, 14]
Challenge 4:
Given a list of numbers, write a list comprehension that produces a list of strings of each number that is
divisible by 5.
numbers=[25, 91, 22, -7, -20]
Challenge 5:
Given a sentence, produce a list of the lengths of each word in the sentence, but only if the word is not
'the'.
sentence='the quick brown fox jumps over the lazy dog'
Challenge 6:
Given a sentence, return the sentence with all vowels removed.
sentence='the quick brown fox jumps over the lazy dog'
Challenge 7:
Given a sentence, return the sentence with all it's letters transposed by 1 in the alphabet, but only if the
letter is a-y.
sentence='the quick brown fox jumps over the lazy dog'
Challenge 8:
Given a list of fruits, use dict comprehension to create a dictionary. The list elements should serve as
the keys and the length of each string as the values.
fruits = ['apple', 'mango', 'banana','cherry']