[2**x for x in range(9)]
list(range(9))
dalist = "the quick brown fox jumped over the lazy dog".split()
dalist
[word.title() for word in dalist ]
[ [word.title(), len(word)] for word in dalist ]
[ len(word) for word in dalist ]
def test1():
return "OK"
def test2():
return "FAIL"
def test3 ():
return "OK"
tests = [test1, test2, test3]
tests
test_run = [t() for t in tests]
test_run
import re
def password_length_is_ok(passw):
if 8<len(passw)<12:
return "OK"
else:
return "Bad length"
def has_special_characters(paslensw):
if re.match(r"[\@\#\$\%\^\&\*]", passw):
return "OK"
else:
return "missing special characters"
password_checks = [password_length_is_ok, has_special_characters]
password = "1234567890"
password_checks_run = [check(password) for check in password_checks ]
password_checks_run
password_checks_run = [ [check.__name__, check(password)] for check in password_checks ]
password_checks_run
len(password_checks)
len(password_checks_run)
deg = [0 , 30, 45, 60, 90]
import math
deg
rad = [d * math.pi/180 for d in deg]
rad
results = [math.sin(r) for r in rad]
["{0:1.2f}".format(r) for r in results]
["{0:1.2f}".format(x) for x in [math.sin(rad) for rad in [ d * math.pi/180 for d in deg ] ]]
["{0:1.2f}".format(math.sin(d*math.pi/180)) for d in deg]
deg = [0,30, 45, 60]
[d + 90*i for i in range(4) for d in deg ]
deg
deg2 = [d+90 for d in deg]
deg2
deg3 = [d+90 for d in deg2]
deg4 = [d+90 for d in deg3]
print(deg)
print(deg2)
print(deg3)
print(deg4)
for i in range(4):
for d in [0, 30, 45, 60]:
print(d + i*90)
deg360 = [ d + i*90 for i in range(4) for d in deg ]
deg360 = [ d + i*90 for d in deg for i in range(4)]
deg360
mydict = { d : "{0:1.2f}".format(math.sin(d*math.pi/180)) for d in deg360}
mydict
[key for key,value in mydict.items()]
[value for key,value in mydict.items()]
thenums= [100, 10000, -9, 9 , -16, 16]
[math.sqrt(num) for num in thenums if num >= 0]
thenums
abs_thenums = [x if x>=0 else -x for x in thenums]
abs_thenums