9-12-23 Notes

Lists

You can add two lists together with the + operator.

cheese = ["parmesean", "pepperjack", "gouda"]
crackers = ["triscuits", "ritz", "saltines"]

cheese_and_crackers = list(zip(cheese, crackers))
flat_list = []

for c in cheese_and_crackers:
	flat_list += list(c)
		
print(cheese_and_crackers)
print(flat_list)

Nested for loop

pairs = [[2, 1], [3, 4]]

for x, y in pairs:
	if x == y:
		same_count = same_count + 1

List comprehension syntax

[<map expression> for <name> in <iter exp> if <filter exp>]

odds = [1,3,5,7,9]
evens_not_two = [(num + 1) for num in odds if num != 2]