Colab

[2**x  for x in range(9)]

[1, 2, 4, 8, 16, 32, 64, 128, 256]
list(range(9))

[0, 1, 2, 3, 4, 5, 6, 7, 8]
dalist = "the quick brown fox jumped over the lazy dog".split()

dalist

['the', 'quick', 'brown', 'fox', 'jumped', 'over', 'the', 'lazy', 'dog']
[word.title()   for word in dalist ]

['The', 'Quick', 'Brown', 'Fox', 'Jumped', 'Over', 'The', 'Lazy', 'Dog']
[ [word.title(), len(word)]   for word in dalist ]

[['The', 3],
 ['Quick', 5],
 ['Brown', 5],
 ['Fox', 3],
 ['Jumped', 6],
 ['Over', 4],
 ['The', 3],
 ['Lazy', 4],
 ['Dog', 3]]
[ len(word)   for word in dalist ]

[3, 5, 5, 3, 6, 4, 3, 4, 3]
def test1():
    return "OK"

def test2():
    return "FAIL"

def test3 ():
    return "OK"


tests = [test1, test2, test3]

tests

[<function __main__.test1()>,
 <function __main__.test2()>,
 <function __main__.test3()>]
test_run = [t()    for t in tests]

test_run

['OK', 'FAIL', 'OK']
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

['OK', 'missing special characters']
password_checks_run = [ [check.__name__, check(password)] for check in password_checks ]

password_checks_run

[['password_length_is_ok', 'OK'],
 ['has_special_characters', 'missing special characters']]
len(password_checks)

2
len(password_checks_run)

2
deg = [0 , 30, 45, 60, 90]

import math
deg


[0, 30, 45, 60, 90]
rad = [d * math.pi/180     for d in deg]

rad

[0.0,
 0.5235987755982988,
 0.7853981633974483,
 1.0471975511965976,
 1.5707963267948966]
results = [math.sin(r) for r in rad]

["{0:1.2f}".format(r) for r in results]

['0.00', '0.50', '0.71', '0.87', '1.00']
["{0:1.2f}".format(x) for x in  [math.sin(rad) for rad in [ d * math.pi/180 for d in deg ] ]]

['0.00', '0.50', '0.71', '0.87', '1.00']
["{0:1.2f}".format(math.sin(d*math.pi/180)) for d in deg]

['0.00', '0.50', '0.71', '0.87', '1.00']
deg = [0,30, 45, 60]

[d + 90*i for i in range(4) for d in deg ]

[0, 30, 45, 60, 90, 120, 135, 150, 180, 210, 225, 240, 270, 300, 315, 330]
deg

[0, 30, 45, 60]
deg2 = [d+90   for d  in deg]

deg2

[90, 120, 135, 150]
deg3 = [d+90   for d  in deg2]

deg4 =  [d+90   for d  in deg3]

print(deg)
print(deg2)
print(deg3)
print(deg4)


[0, 30, 45, 60]
[90, 120, 135, 150]
[180, 210, 225, 240]
[270, 300, 315, 330]
for i in range(4):
    for d in [0, 30, 45, 60]:
        print(d + i*90)

0
30
45
60
90
120
135
150
180
210
225
240
270
300
315
330
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

[0, 30, 45, 60, 90, 120, 135, 150, 180, 210, 225, 240, 270, 300, 315, 330]
mydict = { d : "{0:1.2f}".format(math.sin(d*math.pi/180))   for d in deg360}

mydict

{0: '0.00',
 30: '0.50',
 45: '0.71',
 60: '0.87',
 90: '1.00',
 120: '0.87',
 135: '0.71',
 150: '0.50',
 180: '0.00',
 210: '-0.50',
 225: '-0.71',
 240: '-0.87',
 270: '-1.00',
 300: '-0.87',
 315: '-0.71',
 330: '-0.50'}
[key for key,value in mydict.items()]

[0, 30, 45, 60, 90, 120, 135, 150, 180, 210, 225, 240, 270, 300, 315, 330]
[value for key,value in mydict.items()]

['0.00',
 '0.50',
 '0.71',
 '0.87',
 '1.00',
 '0.87',
 '0.71',
 '0.50',
 '0.00',
 '-0.50',
 '-0.71',
 '-0.87',
 '-1.00',
 '-0.87',
 '-0.71',
 '-0.50']
thenums= [100, 10000, -9, 9 , -16, 16]

[math.sqrt(num) for num in thenums if num >= 0]

[]
thenums

[100, 10000, -9, 9, -16, 16]
abs_thenums = [x if x>=0 else -x for x in thenums]

abs_thenums

[100, 10000, 9, 9, 16, 16]