This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#map,filter,reduce | |
#reduce | |
import functools | |
lst=[1,2,4,54,5,6] | |
num=functools.reduce(lambda x,y:x+y,lst) | |
print(num) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#map,filter,reduce | |
#filter | |
def greater_than5(num): | |
"""this is fun which find the number which is greather than 5""" | |
return num>4 | |
def even(num): | |
"""this function will return the even number""" | |
return num%2==0 | |
if __name__ == '__main__': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#map,filter,reduce | |
#lets take map -we can provide any function to list using map | |
lst=["2","3","4","5","6","7","8"] | |
num=list(map(int,lst)) | |
print(num) | |
num1=list(map(lambda x:x*x,num)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lst=['john cena','randy orton','jindawr mahal','roman'] | |
a="add ".join(lst) | |
print(a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
l1=["cod","pung","counterstrike","minecraft"] | |
import time | |
# i=1 | |
# for item in l1: | |
# if i%2 is not 0: | |
# print("jarvis select nuy this "+item) | |
localtime=time.asctime(time.localtime(time.time())) | |
#use enumerate | |
for index,items in enumerate(l1): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
# intial=time.time() | |
# for i in range(15): | |
# print("hello hey") | |
# time.sleep(2) | |
# print("time taken by this function\n"+str(time.time()-intial)+"seconds") | |
localtime=time.asctime(time.localtime(time.time())) | |
print(localtime) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def function(*args,**kwargs): | |
for i in args: | |
print(i) | |
for k,v in kwargs.items(): | |
print(k,v) | |
har=["harry","carry","marry"] | |
kw={1:"deep",2:"dev"} | |
function(*har,**kw) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# #lambda function | |
minus=lambda x,y:x-y | |
print(minus(3,4)) | |
print("\n") | |
a=[[1,14],[5,6],[2,18]] | |
a.sort(key=lambda x:x[1]) | |
print(a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#snake water gun | |
import random | |
user_option={1:'snake',2:'water',3:'gun'} | |
option=['water','snake','gun',] | |
choice=random.choice(option) | |
def compare(user_ch,comp_ch): | |
"""This function compare the input of user and computer generated input and declare the winner """ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#fibonaci | |
def fibonaci(n): | |
if n==1: | |
return 0 | |
elif n==2: | |
return 1 | |
else: | |
return fibonaci(n-1)+fibonaci(n-2) | |