Skip to content

Instantly share code, notes, and snippets.

# 1. Write code to assign to the variable map_testing all the elements in lst_check
# while adding the string "Fruit: " to the beginning of each element using mapping.
lst_check = ['plums', 'watermelon', 'kiwi', 'strawberries', 'blueberries', 'peaches', 'apples', 'mangos', 'papaya']
map_testing=list(map(lambda item: 'Fruit: ' + item, lst_check))
print (map_testing)
# 2. Below, we have provided a list of strings called countries.
# Use filter to produce a list called b_countries that only contains the strings from countries that begin with B.
# 1. The variable nested contains a nested list. Assign ‘snake’ to the variable output using indexing.
nested = [['dog', 'cat', 'horse'], ['frog', 'turtle', 'snake', 'gecko'], ['hamster', 'gerbil', 'rat', 'ferret']]
output = nested[1][2]
print(output)
# 2. Below, a list of lists is provided. Use in and not in tests to create variables with Boolean values.
# See comments for further instructions.
lst = [['apple', 'orange', 'banana'], [5, 6, 7, 8, 9.9, 10], ['green', 'yellow', 'purple', 'red']]
@Redwoodce
Redwoodce / listOfList.py
Last active January 17, 2023 05:54 — forked from mayankdawar/listOfList.py
Below, we’ve provided a list of lists. Use in statements to create variables with Boolean values - see the ActiveCode window for further directions.
L = [[5, 8, 7], ['hello', 'hi', 'hola'], [6.6, 1.54, 3.99], ['small', 'large']]
# Test if 'hola' is in the list L. Save to variable name test1
test1 = ('hola' in L)
# Test if [5, 8, 7] is in the list L. Save to variable name test2
test2 = ([5, 8, 7] in L)
# Test if 6.6 is in the third element of list L. Save to variable name test3
test3 = (6.6 in L[2])
test3 = False