<jupyter_start><jupyter_text>Generators Generators simplifies creation of iterators. A generator is a function that produces a sequence of results instead of a single value.Each time the yield statement is executed the function generates a new value.**next()** : next is a generator function which takes a generator object and returns it next value 1. Repeatedly calling next function with same gen objects resumes exactly where it left of and continues until it hit the next else statment.<jupyter_code>def simpel_generator():
    print("Hi")
    yield 'Hello'
    x=10
    y=x+5
    print(y)
    yield "World"
    yield x
    
ret=simpel_generator()
print(type(ret))
#print(next(ret))
#print(next(ret))

for i in ret:
    print(i)
def fib_gen(max):
    first,second=0,1
    while first < max:
        yield first
        first,second=second,first+second
gen = fib_gen(1000)

for i in gen:
    print(i)

def fib_gen(max):
    first,second=0,1
    for i in range(0,max):
        yield first
        first,second=second,first+second
gen = fib_gen(19)

for i in gen:
    print(i)<jupyter_output>0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584<jupyter_text>KEYWORD Arguements  Different ways of passing arguements to function<jupyter_code>def employees(e,c,dept='IT',sal=0):
    name=input('enter name of empl:')
    print('name of empl is',name)
    print('emp id:',e)
    print('dept is',dept)
empl_id = 101
#employees(empl_id)
course='dbda'
employees(empl_id,course,'ADMIN',sal=10000)
def employees(e,c,dept='IT',sal=0):
    name=input('enter name of empl:')
    print('name of empl is',name)
    print('emp id:',e)
    print('dept is',dept)
empl_id = 101
#employees(empl_id)
course='dbda'
employees(emp_id,course,dept='ADMIN',sal=10000)
def employees(e,c,dept='IT',sal=0):
    name=input('enter name of empl:')
    print('name of empl is',name)
    print('emp id:',e)
    print('dept is',dept)
empl_id = 101
#employees(empl_id)
course='dbda'
employees(emp_id,course)
def employees(e,*args,dept='IT',sal=0):
    print('Emp ID is',e)
    print('emp id:',args)
empl_id = 101
course='dbda'
employees(empl_id,course,25,dept='Admin',sal=1000)
def employees(*args,dept='IT',sal=0):
    #print(e)
    print('emp id:',args)
empl_id = 101
course='dbda'
employees(empl_id,course,25,dept='Admin',sal=1000)
def employees(*args,**other_info):
    print('All non-key arguements:-> ',args)
    print('All key arguements:-> ',other_info["dept"])
empl_id = 101
course='dbda'
employees(empl_id,course,25,'pune',dept='Admin',sal=1000)<jupyter_output>All non-key arguements:->  (101, 'dbda', 25, 'pune')
All key arguements:->  Admin<jupyter_text>Lambda Functions This is a simple and light weight and un-named.1. It is a single expression function.2. There is no return type3. Anonymous function4. Cann't have doc-string5.  Why Use Lambda Functions?***The power of lambda is better shown when you use them as an anonymous function inside another function.***<jupyter_code>v=lambda x,y: x+y
type(v)
print(v(3,4))
x = lambda a : a + 10
print(x(5))
v=lambda x,y: x-y if x>y else y-x
print(v(3,4))<jupyter_output>1<jupyter_text>MAP The map() function applies a given function to each item of an iterable (list, tuple etc.) and returns a list of the results.**SYNTAX**~~~~map(function, iterable, ...)~~~~  map() Parameter***function - map()*** passes each item of the **iterable** to this function.**iterable** - iterable which is to be mapped 1. ** You can pass more than one iterable to the map() function.<jupyter_code>#Example

def square(x):
    return x**2
print(list(map(square,[1,2,3,4,5])))
def square(x):
    return x**2
res=(map(square,[1,2,3,4,5]))
for i in res:
    print(i)
'''
    Convert a list of strings into list of integers
'''
lst=['23','24','25']
new_lst=list(map(int,lst))
print(new_lst)
#string to ascii
new=list(map(ord,'python is fun'))
print(new)
def surname_based(name):
    return name.split()[1]

students=['<NAME>','<NAME>','<NAME>']
print(students)
students.sort(key=surname_based,reverse=False)
print(students)
students=['<NAME>','<NAME>','<NAME>']
print(students)com
students.sort(key=lambda x:x.split()[1],reverse=False)
print(students)
students=['<NAME>','<NAME>','<NAME>']
x=students
x[0].split()[1]<jupyter_output><empty_output><jupyter_text>SORT Algorithm1. Get a list2. Apply the key3. Sort it4. Arrange<jupyter_code>employees=[['Z',98],['Y',97],['X',96]]
print(employees)
employees.sort(key=lambda x:x[1])
print(employees)
test=['Z',98],['y',87]
test[0]<jupyter_output><empty_output><jupyter_text>SET**Def**-> A set is a  1. Collection of unique elements. 2. Unordered Collections 3. Mutable 4. can't be indexed----------------------------------------------------------*Operations on Sets*1. Union2. Intersection3. Differeence<jupyter_code>my_set={1,2,3,3,4,5,6,6,6,7}
my_set
dir(my_set)
my_set.add((123,5,6))
my_set
eng={'A','B','C'}
prog={'D','E','F'}
eng - prog
fs=frozenset(['a','b'])
fs
type(fs)
lc = [ x for x in range(10) if x%2==0 ]
lc
lc = { x for x in range(10) if x%2==0 }
lc
lc<jupyter_output><empty_output><jupyter_text>Modules     If you quit from the Python interpreter and enter it again, the definitions you have made (functions and variables) are lost. Therefore, if you want to write a somewhat longer program, you are better off using a text editor to prepare the input for the interpreter and running it with that file as input instead. This is known as creating a script. As your program gets longer, you may want to split it into several files for easier maintenance. You may also want to use a handy function that you’ve written in several programs without copying its definition into each program.    To support this, Python has a way to put definitions in a file and use them in a script or in an interactive instance of the interpreter. Such a file is called a module; definitions from a module can be imported into other modules or into the main module (the collection of variables that you have access to in a script executed at the top level and in calculator mode).    A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. Within a module, the module’s name (as a string) is available as the value of the global variable __name__. For instance, use your favorite text editor to create a file called fibo.py in the current directory with the following contents:    ~~~~ Fibonacci numbers moduledef fib(n):     write Fibonacci series up to n    a, b = 0, 1    while b < n:        print b,        a, b = b, a+bdef fib2(n):    return Fibonacci series up to n    result = []    a, b = 0, 1    while b < n:        result.append(b)        a, b = b, a+b    return result~~~~<jupyter_code># WAP To calculate area of a circle
from math import pi
def acircle(radius):
    return pi*radius**2
def ccircle(radius):
    return 2*pi*radius

acircle(4)

ccircle(4)
%time
from math import pi
print(pi*4**2)
%time
from math import pi
print(pi*4*4)<jupyter_output>CPU times: user 2 µs, sys: 0 ns, total: 2 µs
Wall time: 4.77 µs
50.26548245743669
{'fraction_non_alphanumeric': 0.13743270048172287, 'fraction_numerical': 0.03230376877302352, 'mean_word_length': 4.642685851318944, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '606538', 'license': 'MIT', 'n_tokens_mistral': 2543, 'n_tokens_neox': 2383, 'n_words': 816, 'path': 'Mod04-Python/ClassNotes/Day4.ipynb', 'repo_name': 'kambleaa007/PG-DBDA', 'size': '7109'}