Skip to content
Snippets Groups Projects
Commit ced716ff authored by W. Spencer Smith's avatar W. Spencer Smith
Browse files

Starting point for L17 examples.

parent 4491728a
No related branches found
No related tags found
No related merge requests found
......@@ -7,4 +7,31 @@ L2 = [x*2 for x in range(1, 11) if x*2 >= 12]
# List Comp to find List Length
def length(xs):
return sum([1 for x in xs])
return sum([1 for anything in xs])
def rep(x, n):
return [x for something in range(n)]
def even(x):
return x%2==0
def odd(x):
return not(even(x))
def boomBangs(xs):
return ["BOOM" if x < 10 else "BANG" for x in xs if odd(x)]
# List Comprehension With Two Lists
nouns = ["hobo", "frog", "pope"]
adjectives = ["lazy", "grouchy", "scheming"]
L3 = [adjective + ' ' + noun for noun in nouns for adjective in adjectives]
# Remove non UpperCase
def removeNonUpperCase(st):
upCase = [chr(i) for i in range(ord('A'), ord('Z')+1)]
return [c for c in st if c in upCase]
xxs = [[1,3,5,2,3,1,2,4,5],[1,2,3,4,5,6,7,8,9],[1,2,4,2,1,6,3,1,3,2,3,6]]
L4 = [[x for x in xs if even(x)] for xs in xxs ]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment