# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # *for loops

seq = [1,2,3,4,5]

for num in seq:
    print("i am number {}".format(num))

# # *while loops

# +
i = 1

while i<5:
    print("hello my number {}".format(i))
    i+=1
    

# -

# some usefull functions in python

# # *Range()

# lets see the old tradional way of keeping a sequnce of characters in loops : 

for num in seq:
    print(num)

# instead we use a range function. Which is like a generator of numerical values
#

for num in range(1,10):
    print("{} is my lucky number ".format(num))

list(range(10))

# # List Comprehension

# this will help or allow you to save a bunch of writting

x = [1,2,3,4,5]

# here i want to produce a list with squared values of the original list of x

# +
out = []

for num in x:
    out.append(num**2)
# -

print(out)

# Now we're going to translate the above procedures by implementing a list comprehension

[num**2 for num in x]

# so simply we can put the above idea in the following manner

out = [num**2 for num in x]

print(out)


# Hence all those two methods produce the same thing.But list comprehession will save more time for you 

#
#
#  

# # functions

# + active=""
# for the syntax
#     def function_name(parameters_1):
#         print(parameter_1)
#         
# To call the function for use, we use the following syntax
# => function_name(parameter_1)
# -

def my_func(par:str):
    print(par)


my_func("hello")


# * Now lets create a function named square,that takes in a number and returns the square of that number

def square(num):
    """
    This is a doc multiline string
    and this function squares a number passed a parameter
    """
    return num**2


square(6)

the_square_is = square(num)

print(the_square_is)


# now if you want to see my documntation string you have to write, the function name and press shift + tab

#

# # Map 

# now lets begin by creating a function

def times2(var):
    return var*2


times2(5)

# *now for the map function/

#creating a sequence named seq
seq = [1,2,3,4,5]

# * map is a built in function in python, that allows you to save the step of initiializing a for loop and saving the results in another function

map(times2,seq)

# * the above out[34], describes that we have a map at location 0x7f0d13b3bb80

# now lets cast this into a list by using boilt in function 

list(map(times2,seq))

#  
#     
#     
#     
# # Lambda Expression

#     now here what we do is, we use the times2 function above to make a new function powered by lambda expression

lambda var:var*2

# * so we can assign the expression in a variable, then use the variable to act as ordinary calling of functions

t = lambda var:var*2

t(4)

# Lambda expressions are normally used in maps..

list(map(lambda num:num*2,seq))





#
# #  filter() built in function 

# the filter function does have similar structure to the map function, but instead of using the function for evey single element in the list, this will filter them out instead

filter(lambda num:num%2 == 0,seq)

# * In order to get the results back, we have to cast the filter function into a list

list(filter(lambda num:num%2 == 0, seq))

#
#
# # Some String Methods

# consider the following string and the use of the methods within 

s = "hello, my name is Joseph"

# * s.lower



StarcoderdataJupyterScriptsDedupFiltered