<jupyter_start><jupyter_text>Day16 Comprehensions, lambda, Iterators, Generators, Map and Filter  Recap- Regular Expressions    - re        - findall        - sub -> replace        - subn        - match Today Objectives- Functional Programming/ Comprehensions- lambda function/ nameless Function/ anoyonomous function- Iterator- Generator- map()- filter()- reduce()  Functional Programing- List Comprehension- Dictionary Comprehension- tuple Comprehension- set comprehension<jupyter_code>li = []
for i in range(1, 101):
    li.append(i)
print(li)
li = []
for i in range(1, 101):
    if i % 2 == 0 or i % 3 == 0:
        li.append(i)
print(li)<jupyter_output>[2, 3, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 26, 27, 28, 30, 32, 33, 34, 36, 38, 39, 40, 42, 44, 45, 46, 48, 50, 51, 52, 54, 56, 57, 58, 60, 62, 63, 64, 66, 68, 69, 70, 72, 74, 75, 76, 78, 80, 81, 82, 84, 86, 87, 88, 90, 92, 93, 94, 96, 98, 99, 100]<jupyter_text>List Comprehensions Syntax```[ele for IterVar in groupOfElements]```<jupyter_code>li = [i for i in range(1, 101)]


print(li)
li = [[i] for i in range(1, 101)]


print(li)
li = ['*' for i in range(1, 101)]


print(li)
li = [i for i in range(1, 101) if i % 2 == 0]

print(li)

li = [year for year in range(2000, 3000) if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0)]


print(li)
li = ['even' if i % 2 == 0 else 'odd' for i in range(2000, 3000)]


print(li)
def square(num):
    return num ** 2
li = [square(i) for i in range(1, 101)]


print(li)
def square(num):
    return cube(num ** 2)


def cube(sq):
    return sq ** 3
li = [square(i) for i in range(1, 101)]


print(li)
def square(num):
    return num ** 2


def cube(sq):
    return sq ** 3

li = [cube(square(i)) for i in range(1, 101)]


print(li)
li = [[i for i in range(1, 6)] for j in range(5)]
li
li = [[i for i in range(1, 6)] for j in range(100)]

li
li = [[j for i in range(1, 6)] for j in range(1, 6)]

li
li = [[[j for i in range(1, 6)] for j in range(1, 6)] for k in range(5)]

li
s = """Python is an interpreted high-level general-purpose programming language. Python's design philosophy emphasizes code readability with its notable use of significant indentation. Wikipedia
Developer: Python Software Foundation
Stable release: 3.9.5 / 3 May 2021; 29 days ago
Preview release: 3.10.0b1 / 3 May 2021; 29 days ago
Typing discipline: Duck, dynamic, strong typing; gradual (since 3.5, but ignored in CPython)
First appeared: February 1991; 30 years ago
Paradigm: Multi-paradigm: object-oriented, procedural (imperative), functional, structured, reflective"""
up = [char for char in s if char.isupper()]
print(up)
vol = [char for char in s if char in 'aeiou']


print(vol)
vol = [char for char in s if char in 'aeiouAEIOU']

print(vol)
vol = [char for char in s if char.lower() in 'aeiou']

print(vol)<jupyter_output>['o', 'i', 'a', 'i', 'e', 'e', 'e', 'i', 'e', 'e', 'e', 'e', 'a', 'u', 'o', 'e', 'o', 'a', 'i', 'a', 'u', 'a', 'e', 'o', 'e', 'i', 'i', 'o', 'o', 'e', 'a', 'i', 'e', 'o', 'e', 'e', 'a', 'a', 'i', 'i', 'i', 'i', 'o', 'a', 'e', 'u', 'e', 'o', 'i', 'i', 'i', 'a', 'i', 'e', 'a', 'i', 'o', 'i', 'i', 'e', 'i', 'a', 'e', 'e', 'o', 'e', 'o', 'o', 'a', 'e', 'o', 'u', 'a', 'i', 'o', 'a', 'e', 'e', 'e', 'a', 'e', 'a', 'a', 'a', 'o', 'e', 'i', 'e', 'e', 'e', 'a', 'e', 'a', 'a', 'a', 'o', 'i', 'i', 'i', 'i', 'e', 'u', 'a', 'i', 'o', 'i', 'a', 'u', 'a', 'i', 'e', 'u', 'i', 'o', 'e', 'i', 'o', 'i', 'a', 'e', 'a', 'e', 'e', 'u', 'a', 'e', 'a', 'a', 'o', 'a', 'a', 'i', 'u', 'i', 'a', 'a', 'i', 'o', 'e', 'o', 'i', 'e', 'e', 'o', 'e', 'u', 'a', 'i', 'e', 'a', 'i', 'e', 'u', 'i', 'o', 'a', 'u', 'u', 'e', 'e', 'e', 'i', 'e']<jupyter_text>Dictionary Comprehensions create a dictionary key as the number and value as the square of the number of 1 - 100<jupyter_code>di = {}
for num in range(1, 101):
    di[num] = num ** 2

print(di)
di = {i: i ** 2 for i in range(1, 101)}

print(di)
di = {i: i + 5 for i in range(1, 101)}

print(di)<jupyter_output>{1: 6, 2: 7, 3: 8, 4: 9, 5: 10, 6: 11, 7: 12, 8: 13, 9: 14, 10: 15, 11: 16, 12: 17, 13: 18, 14: 19, 15: 20, 16: 21, 17: 22, 18: 23, 19: 24, 20: 25, 21: 26, 22: 27, 23: 28, 24: 29, 25: 30, 26: 31, 27: 32, 28: 33, 29: 34, 30: 35, 31: 36, 32: 37, 33: 38, 34: 39, 35: 40, 36: 41, 37: 42, 38: 43, 39: 44, 40: 45, 41: 46, 42: 47, 43: 48, 44: 49, 45: 50, 46: 51, 47: 52, 48: 53, 49: 54, 50: 55, 51: 56, 52: 57, 53: 58, 54: 59, 55: 60, 56: 61, 57: 62, 58: 63, 59: 64, 60: 65, 61: 66, 62: 67, 63: 68, 64: 69, 65: 70, 66: 71, 67: 72, 68: 73, 69: 74, 70: 75, 71: 76, 72: 77, 73: 78, 74: 79, 75: 80, 76: 81, 77: 82, 78: 83, 79: 84, 80: 85, 81: 86, 82: 87, 83: 88, 84: 89, 85: 90, 86: 91, 87: 92, 88: 93, 89: 94, 90: 95, 91: 96, 92: 97, 93: 98, 94: 99, 95: 100, 96: 101, 97: 102, 98: 103, 99: 104, 100: 105}<jupyter_text>key as the num and value as the sq of previous number<jupyter_code>di = {i: (i - 1) ** 2 for i in range(1, 101)}

print(di)
di = {i: i ** 2 for i in range(1, 101) if i % 2 == 0}

print(di)
di = {i: 'Even' if i % 2 == 0 else 'odd' for i in range(1, 101)}

print(di)<jupyter_output>{1: 'odd', 2: 'Even', 3: 'odd', 4: 'Even', 5: 'odd', 6: 'Even', 7: 'odd', 8: 'Even', 9: 'odd', 10: 'Even', 11: 'odd', 12: 'Even', 13: 'odd', 14: 'Even', 15: 'odd', 16: 'Even', 17: 'odd', 18: 'Even', 19: 'odd', 20: 'Even', 21: 'odd', 22: 'Even', 23: 'odd', 24: 'Even', 25: 'odd', 26: 'Even', 27: 'odd', 28: 'Even', 29: 'odd', 30: 'Even', 31: 'odd', 32: 'Even', 33: 'odd', 34: 'Even', 35: 'odd', 36: 'Even', 37: 'odd', 38: 'Even', 39: 'odd', 40: 'Even', 41: 'odd', 42: 'Even', 43: 'odd', 44: 'Even', 45: 'odd', 46: 'Even', 47: 'odd', 48: 'Even', 49: 'odd', 50: 'Even', 51: 'odd', 52: 'Even', 53: 'odd', 54: 'Even', 55: 'odd', 56: 'Even', 57: 'odd', 58: 'Even', 59: 'odd', 60: 'Even', 61: 'odd', 62: 'Even', 63: 'odd', 64: 'Even', 65: 'odd', 66: 'Even', 67: 'odd', 68: 'Even', 69: 'odd', 70: 'Even', 71: 'odd', 72: 'Even', 73: 'odd', 74: 'Even', 75: 'odd', 76: 'Even', 77: 'odd', 78: 'Even', 79: 'odd', 80: 'Even', 81: 'odd', 82: 'Even', 83: 'odd', 84: 'Even', 85: 'odd', 86: 'Even', 87: 'odd', 88: 'Eve[...]<jupyter_text>{1: [1], 2:[1,2], 3:[1,2,3], 4:[1,2,3,4], 5:[1,2,3,4,5] ...... 100}<jupyter_code>di = {i: [num for num in range(1, i + 1)] for i in range(1, 101)}

print(di)
di = {i: ['*' for num in range(1, i + 1)] for i in range(1, 101)}

di
100 * (100 + 1)
li = [i for i in range(1, 101)]

di = {i: li[ : i + 1] for i in range(1, 101)}

di<jupyter_output><empty_output><jupyter_text>set comprehensions<jupyter_code>s1 = {char for char in s}
print(s1)
s1 = {char for char in s if char.isalnum()}

print(s1)
t1 = (i for i in range(1, 101))

print(t1)<jupyter_output><generator object <genexpr> at 0x000001CD60F85120><jupyter_text>Nameless Function<jupyter_code>def funName(arg):
    pass
funName(6656)
def funName(arg):

def square(num):
    return num ** 2
sq = lambda num: num ** 2
print(square(5))

print(sq(5))
mul = lambda a, b: a ** 2 + b ** 2 + 2 * a * b
mul(5, 5)
for i in range(1, 101):
    print(mul(i, i + 1))
sq1 = lambda a: sq(a)
print(sq1(5))<jupyter_output>25<jupyter_text>map()<jupyter_code>inp = input()

print(inp)
inp
li = inp.split()


print(li)
s = 0
inp = input()
li = inp.split()
for i in li:
    s += int(i)
print(s)<jupyter_output>1 2 3 4 5 6 7 8 9 10
55<jupyter_text>map()map(function, seqofData)It returns map object -> list/tuple/set<jupyter_code>li = map(int, input().split())

print(li)
li = list(li)


print(li, sum(li))
s = sum(list(map(int, input().split())))

print(li)
print(s)
li = map(list, input().split())

print(list(li))
li = map(lambda x: x[0], input().split())

print(list(li))
li = map(lambda x: int(x[0]), input().split())

print(list(li))
li = map(lambda x: x[0], input().split())

print(list(li))<jupyter_output>11 12 5 6 4 7 8 10 13 4 6 56
['1', '1', '5', '6', '4', '7', '8', '1', '1', '4', '6', '5']<jupyter_text>int object is not callable error<jupyter_code>for i in 55:
    print(i)
sum(55)
L1= list(map(int, input().split()))
print(L1, sum(L1))
import sys

sys.version
print(55[0])<jupyter_output><>:1: SyntaxWarning: 'int' object is not subscriptable; perhaps you missed a comma?
<>:1: SyntaxWarning: 'int' object is not subscriptable; perhaps you missed a comma?
<ipython-input-91-2cf7ba6c1ef0>:1: SyntaxWarning: 'int' object is not subscriptable; perhaps you missed a comma?
  print(55[0])<jupyter_text>filter()filter(function, iterables) sum the even numbers from the input<jupyter_code>fi = filter(lambda x: int(x) % 2 == 0, input().split())
print(list(fi))
s = """Python is an interpreted high-level general-purpose programming language. Python's design philosophy emphasizes code readability with its notable use of significant indentation. Wikipedia
Developer: Python Software Foundation
Stable release: 3.9.5 / 3 May 2021; 29 days ago
Preview release: 3.10.0b1 / 3 May 2021; 29 days ago
Typing discipline: Duck, dynamic, strong typing; gradual (since 3.5, but ignored in CPython)
First appeared: February 1991; 30 years ago
Paradigm: Multi-paradigm: object-oriented, procedural (imperative), functional, structured, reflective"""
fi = list(filter(lambda x: x.isupper(), s))

print(fi)
sq = lambda num: num ** 2
sq(5)
sq = lambda num: [num ** 2, num ** 3, num ** 4]
sq(5)
print(list(filter(lambda x: x.islower(), s)))
print(list(map(lambda x: x.islower(), s)))
list(filter(lambda x: x.islower(), input()))<jupyter_output>dbvdbvSDBFKJSDBVKdnfkjvbdk
{'fraction_non_alphanumeric': 0.22718052738336714, 'fraction_numerical': 0.11284295932529091, 'mean_word_length': 4.169977924944813, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 59, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '63564', 'license': 'CC0-1.0', 'n_tokens_mistral': 4916, 'n_tokens_neox': 3914, 'n_words': 1453, 'path': 'Notebooks/Day16_Comprehensions_and_Special_Functions_in_Python.ipynb', 'repo_name': 'nandakishore1807/Data-Science-Using-Python-Internship-EB1', 'size': '9367'}