<jupyter_start><jupyter_text>Ternary operation<jupyter_code>is_friend = True
can_message = "message allowed" if is_friend else "message no allowed!"
print(can_message)<jupyter_output>message allowed<jupyter_text>`is vs ==` The is keyword is used to test if two variables refer to the same object. The test returns True if the two objects are the same object. The test returns False if they are not the same object, even if the two objects are 100% equal. Use the == operator to test if two variables are equal.<jupyter_code>print([] == [])
print([] is [])<jupyter_output>False<jupyter_text>Here whats happening is that , all ds will gets created in different m/m spaces. So `is` checks whether we are comparing the exact same thing<jupyter_code>print(1 is 1)
print('10' == 10)
print('10' is 10)
print([1] == [1])<jupyter_output>True<jupyter_text>`range()`<jupyter_code>print(list(range(10)))<jupyter_output>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]<jupyter_text>`enumerate()` To get index along with the iterable<jupyter_code>for i,char in enumerate('Hellooooooooo'):
    print(i,char)
    
    
for char in enumerate("Hellllooooo"):
    print(char)
for item in enumerate([12,24,36,64]):
    print(item)
for i,item in enumerate(list(range(100))):
    if item == 50:
        print(f'Index of 50 is: {i}')
picture = [[0,0,0,1,0,0,0],
           [0,0,1,1,1,0,0],
           [0,1,1,1,1,1,0],
           [1,1,1,1,1,1,1],
           [0,0,0,1,0,0,0],
           [0,0,0,1,0,0,0]]<jupyter_output><empty_output><jupyter_text>Christmas tree<jupyter_code>for row in picture:
    for pixel in row:
        if pixel == 1:
            print('*',end='')
        else:
            print('',end='')
    print('')<jupyter_output>*
***
*****
*******
*
*<jupyter_text>Duplicate Remover<jupyter_code>dl = [12,11,11,15,23,12,44,67,23]
em = []
for i in dl:
    if dl.count(i)>1:
        if i not in em:
            em.append(i)
em<jupyter_output><empty_output><jupyter_text>Psych Function<jupyter_code>def sum2(num1,num2):
    def another_func(n1,n2):
        return n1+n2
    return another_func(num1,num2)
tot = sum2(10,20)
print(tot)<jupyter_output>30<jupyter_text>Making Docstrings<jupyter_code>def sum_of_numbers():
    '''
    Info:This function can be used to find sum of numbers
    '''
    return sum
sum_of_numbers()
help(sum_of_numbers)
print(sum_of_numbers.__doc__)<jupyter_output>Info:This function can be used to find sum of numbers<jupyter_text>`*args` & `**kwargs`<jupyter_code>## args
# in some cases where we doubt how many parameters to 
# be given while defining a function 
# *args can be used
def super_func(*args):
    return sum(args)
t = super_func(12,34,56)
print(t)
# **kwargs
# kwargs allows us to pass keywords as arguments
def super_func_k(*args,**kwargs):
    tot=0
    for items in kwargs.values():
        tot+=items
    return sum(args)+tot
t = super_func_k(12,34,56, num1=10,num2=20)
print(t)<jupyter_output>132<jupyter_text>Order for parameters in a function  params, *args , default params , **kwargs  Exercise: Find the highest even in a passed list<jupyter_code>def highest_even(psd_lt):
    hig = psd_lt[0]
    for items in psd_lt:
        if items%2==0 and items>=hig:
            print(items)
            
highest_even([1,23,14,3,9])<jupyter_output>14<jupyter_text>`global` keyword<jupyter_code>tot = 0
def count_items(item):
    global tot
    tot+=item
    return tot
print(count_items(2))
print(tot)
# Best Practise -> Dependency Injection
total = 0
def dep_inj(total):
    total+=1
    return total
print(dep_inj(dep_inj(dep_inj(total))))
print(total)<jupyter_output>3
0<jupyter_text>What if we didnt used `global` or `dependency injection`<jupyter_code>totl=0
def count_items_mod():
    totl+=1
    return totl
print(count_items_mod())<jupyter_output><empty_output><jupyter_text>`nonlocal`<jupyter_code>def outer():
    x = 'local'
    def inner():
        nonlocal x
        x = 'nonlocal'
        print('inner:',x)
    inner()
    print('outer:',x)
outer()<jupyter_output>inner: nonlocal
outer: nonlocal<jupyter_text>Without nonlocal<jupyter_code>def outer():
    x = 'local'
    def inner():
        #nonlocal x
        x = 'nonlocal'
        print('inner:',x)
    inner()
    print('outer:',x)
outer()<jupyter_output>inner: nonlocal
outer: local
{'fraction_non_alphanumeric': 0.13776108894625674, 'fraction_numerical': 0.03801924430884769, 'mean_word_length': 4.307596513075965, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '481005', 'license': 'MIT', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1577, 'n_words': 381, 'path': 'General_Stuffs.ipynb', 'repo_name': 'binarymatter/Python_HandBook', 'size': '4261'}