<jupyter_start><jupyter_text>Quiz 1 Loan Pham and <NAME> Q.1 Create the following lists: first_name=["Mary","James","Peter","Yoyo"] last_name=["Brown","White","Reed","Holt"].<jupyter_code>#Q.1
first_name=["Mary","James","Peter","Yoyo"]
last_name=["Brown","White","Reed","Holt"]<jupyter_output><empty_output><jupyter_text>(a) Create a list of pairs with the last name and then the first name in each pair. Display the list.<jupyter_code>#Q.1.a
pairs=[0,0,0,0]
for i in range(len(pairs)):
    pairs[i] = first_name[i]+" "+last_name[i]
print(pairs)<jupyter_output>['<NAME>', '<NAME>', '<NAME>', '<NAME>']<jupyter_text>(b) Create a dictionary by counting the number of vowels in each of the first names. The keys should be thefirst names and the values should be the number of vowels.<jupyter_code>#Q.1.b
def vowelcount(list):
    #add/remove 'y' and 'Y' for "sometimes Y" switch default=on
    return sum([1 for char in ''.join(list) if char in 'aeiouyAEIOUY'])
vowelCountByName = dict.fromkeys(first_name,0)
for name in first_name:
    vowelCountByName[name] = vowelcount(name)

print(vowelCountByName)<jupyter_output>{'Mary': 2, 'James': 2, 'Peter': 2, 'Yoyo': 4}<jupyter_text>(c) for the list in (a), access the last two elements<jupyter_code>#Q.1.c
print(pairs[2]+", "+pairs[3])<jupyter_output><NAME>, <NAME><jupyter_text>(d) for the list in (a), sort it in descending order of last name.<jupyter_code>#Q.1.d
print (pairs)
pairs.sort(key=lambda ws: ws.split(" ")[1], reverse=True)
print(pairs)<jupyter_output>['<NAME>', '<NAME>', '<NAME>', '<NAME>']
['<NAME>', '<NAME>', '<NAME>', '<NAME>']<jupyter_text>Q.2 Create a list of 100 pairs of numbers. In each pair, the first number is a random integer between 0 and 50.The second number is also a random integer between 0 and 50. Extracts the pairs with the first number less thanthe second number.<jupyter_code>#Q.2
import random
oneHundredNumberPairs=[(random.randrange(0,49), random.randrange(0,49)) for _ in range (100)]
print(oneHundredNumberPairs)
matchingPairs = [x for x in oneHundredNumberPairs if x[0] < x[1]]
print("Match!")
print(matchingPairs)<jupyter_output>[(8, 32), (31, 7), (3, 36), (47, 13), (29, 8), (17, 26), (21, 1), (33, 31), (47, 34), (14, 43), (27, 29), (13, 3), (2, 39), (21, 40), (17, 8), (37, 22), (2, 42), (17, 3), (41, 23), (38, 9), (0, 24), (33, 17), (25, 39), (26, 26), (11, 7), (29, 1), (13, 46), (24, 44), (45, 0), (5, 13), (3, 42), (1, 31), (15, 32), (38, 37), (3, 34), (40, 26), (35, 48), (22, 9), (27, 32), (8, 15), (40, 26), (38, 10), (42, 3), (20, 18), (39, 45), (8, 11), (42, 19), (40, 39), (4, 15), (43, 44), (31, 27), (44, 34), (45, 44), (34, 18), (22, 31), (7, 37), (8, 11), (40, 13), (38, 43), (43, 18), (6, 13), (46, 3), (33, 48), (8, 31), (2, 6), (36, 0), (20, 18), (7, 15), (36, 3), (1, 44), (30, 13), (6, 38), (1, 46), (33, 41), (37, 11), (27, 1), (44, 19), (0, 41), (31, 48), (41, 45), (9, 15), (25, 38), (0, 25), (34, 13), (30, 20), (3, 45), (22, 0), (24, 42), (35, 36), (23, 27), (5, 29), (35, 11), (10, 19), (35, 45), (19, 16), (13, 44), (46, 32), (40, 25), (46, 5), (14, 42)]
Match!
[(8, 32), (3, 36), (17, 26), (14, 43)[...]
StarcoderdataJupyterStructuredCleanDedup