Python 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. DreamPie 1.2.1 >>> xs = 'abrakadabra' >>> set(xs) 0: {'b', 'k', 'r', 'a', 'd'} >>> ys = set() >>> ys = [] ... for x in xs: ... if x not in ys: ... ys.append(x) >>> ys 1: ['a', 'b', 'r', 'k', 'd'] >>> zs = [x for x in xs] >>> zs 2: ['a', 'b', 'r', 'a', 'k', 'a', 'd', 'a', 'b', 'r', 'a'] >>> zs = {x for x in xs} >>> zs 3: {'b', 'k', 'r', 'a', 'd'} >>> zs = [x for x in xs if x not in 'aeiou'] >>> zs 4: ['b', 'r', 'k', 'd', 'b', 'r'] >>> [(x,y) for x in range(1, 4) for y in 'abc'] 5: [(1, 'a'), (1, 'b'), (1, 'c'), (2, 'a'), (2, 'b'), (2, 'c'), (3, 'a'), (3, 'b'), (3, 'c')] >>> [(x,y,z) for x in range(1, 4) for y in 'abc' for z in 'ABC'] 6: [(1, 'a', 'A'), (1, 'a', 'B'), (1, 'a', 'C'), (1, 'b', 'A'), (1, 'b', 'B'), (1, 'b', 'C'), (1, 'c', 'A'), (1, 'c', 'B'), (1, 'c', 'C'), (2, 'a', 'A'), (2, 'a', 'B'), (2, 'a', 'C'), (2, 'b', 'A'), (2, 'b', 'B'), (2, 'b', 'C'), (2, 'c', 'A'), (2, 'c', 'B'), (2, 'c', 'C'), (3, 'a', 'A'), (3, 'a', 'B'), (3, 'a', 'C'), (3, 'b', 'A'), (3, 'b', 'B'), (3, 'b', 'C'), (3, 'c', 'A'), (3, 'c', 'B'), (3, 'c', 'C')] >>> [(x,y) for x,y in zip('abc', '123')] 7: [('a', '1'), ('b', '2'), ('c', '3')] >>> [(x,y) for x,y in zip('abc', '12345')] 8: [('a', '1'), ('b', '2'), ('c', '3')] >>> [(x,y,z) for x,y,z in zip('abc', '12345', 'ABC')] 9: [('a', '1', 'A'), ('b', '2', 'B'), ('c', '3', 'C')] >>> [(x,) for x in zip('abc', )] 10: [(('a',),), (('b',),), (('c',),)] >>> xs = [1, 4, 2, 67, 2, -90, 456, 2, 1, 45, 5, 6, 7, 9, -3, 2, 4, 5, 61] >>> [x**3 for x in xs] 11: [1, 64, 8, 300763, 8, -729000, 94818816, 8, 1, 91125, 125, 216, 343, 729, -27, 8, 64, 125, 226981] >>> import math >>> [math.log10(x) for x in xs] Traceback (most recent call last): File "<pyshell#20>", line 1, in <module> [math.log10(x) for x in xs] ~~~~~~~~~~^^^ ValueError: math domain error >>> xs 12: [1, 4, 2, 67, 2, -90, 456, 2, 1, 45, 5, 6, 7, 9, -3, 2, 4, 5, 61] >>> [math.log10(x) for x in xs if x > 0] 13: [0.0, 0.6020599913279624, 0.3010299956639812, 1.8260748027008264, 0.3010299956639812, 2.658964842664435, 0.3010299956639812, 0.0, 1.6532125137753437, 0.6989700043360189, 0.7781512503836436, 0.8450980400142568, 0.9542425094393249, 0.3010299956639812, 0.6020599913279624, 0.6989700043360189, 1.7853298350107671] >>> [x for x in xs if x % 2 == 0] 14: [4, 2, 2, -90, 456, 2, 6, 2, 4] >>> [x for x in xs if (x % 2 == 0) or (x % 3 == 0)] 15: [4, 2, 2, -90, 456, 2, 45, 6, 9, -3, 2, 4] >>> [x for x in xs if x % 2 == 0 or x % 3 == 0] 16: [4, 2, 2, -90, 456, 2, 45, 6, 9, -3, 2, 4] >>> [str(x) for x in xs] 17: ['1', '4', '2', '67', '2', '-90', '456', '2', '1', '45', '5', '6', '7', '9', '-3', '2', '4', '5', '61'] >>> [f'{str(x):>4}' for x in xs] 18: [' 1', ' 4', ' 2', ' 67', ' 2', ' -90', ' 456', ' 2', ' 1', ' 45', ' 5', ' 6', ' 7', ' 9', ' -3', ' 2', ' 4', ' 5', ' 61'] >>> [f'{x:>4}' for x in xs] 19: [' 1', ' 4', ' 2', ' 67', ' 2', ' -90', ' 456', ' 2', ' 1', ' 45', ' 5', ' 6', ' 7', ' 9', ' -3', ' 2', ' 4', ' 5', ' 61'] >>> [f'{x:*>4}' for x in xs] 20: ['***1', '***4', '***2', '**67', '***2', '*-90', '*456', '***2', '***1', '**45', '***5', '***6', '***7', '***9', '**-3', '***2', '***4', '***5', '**61'] >>> [x for x in xs if x**2 > 100] 21: [67, -90, 456, 45, 61] >>> xs 22: [1, 4, 2, 67, 2, -90, 456, 2, 1, 45, 5, 6, 7, 9, -3, 2, 4, 5, 61] >>> [x for x in xs if x**2 <= 100] 23: [1, 4, 2, 2, 2, 1, 5, 6, 7, 9, -3, 2, 4, 5] >>> [(x, x**2, x**3) for x in xs if x < 100] 24: [(1, 1, 1), (4, 16, 64), (2, 4, 8), (67, 4489, 300763), (2, 4, 8), (-90, 8100, -729000), (2, 4, 8), (1, 1, 1), (45, 2025, 91125), (5, 25, 125), (6, 36, 216), (7, 49, 343), (9, 81, 729), (-3, 9, -27), (2, 4, 8), (4, 16, 64), (5, 25, 125), (61, 3721, 226981)] >>> {x:str(x) for x in xs if x < 100} 25: {-90: '-90', -3: '-3', 1: '1', 2: '2', 4: '4', 5: '5', 6: '6', 7: '7', 9: '9', 45: '45', 61: '61', 67: '67'} >>> ws = ["dog", "pig", "hippo", "dogs", "tyranosaurus", "human", "shark", "lion"] >>> [... for w in ws] 26: [Ellipsis, Ellipsis, Ellipsis, Ellipsis, Ellipsis, Ellipsis, Ellipsis, Ellipsis] >>> [w for w in ws] 27: ['dog', 'pig', 'hippo', 'dogs', 'tyranosaurus', 'human', 'shark', 'lion'] >>> [len(w) for w in ws] 28: [3, 3, 5, 4, 12, 5, 5, 4] >>> sum([len(w) for w in ws]) 29: 41 >>> sum(len(w) for w in ws) 30: 41 >>> [w.upper() for w in ws] 31: ['DOG', 'PIG', 'HIPPO', 'DOGS', 'TYRANOSAURUS', 'HUMAN', 'SHARK', 'LION'] >>> [w.capitalize() for w in ws] 32: ['Dog', 'Pig', 'Hippo', 'Dogs', 'Tyranosaurus', 'Human', 'Shark', 'Lion'] >>> [w.capitalize() for w in ws if len(w) > 3] 33: ['Hippo', 'Dogs', 'Tyranosaurus', 'Human', 'Shark', 'Lion'] >>> [(w.capitalize() if len(w) > 3 else w) for w in ws if len(w) > 3] 34: ['Hippo', 'Dogs', 'Tyranosaurus', 'Human', 'Shark', 'Lion'] >>> [(w.capitalize() if len(w) > 3 else w) for w in ws] 35: ['dog', 'pig', 'Hippo', 'Dogs', 'Tyranosaurus', 'Human', 'Shark', 'Lion'] >>> [w for w in ws if w.endswith('s')] 36: ['dogs', 'tyranosaurus'] >>> a, b = [], [0] >>> a and b 37: [] >>> if a and b: ... print(True) ... else: ... print(False) False >>> a or b 38: [0] >>> if a or b: ... print(True) ... else: ... print(False) True >>>