This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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']] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |