Skip to content

Instantly share code, notes, and snippets.

View Deep18-03's full-sized avatar
🏠
Working from home

Deep18-03

🏠
Working from home
View GitHub Profile
#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__':
#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))
lst=['john cena','randy orton','jindawr mahal','roman']
a="add ".join(lst)
print(a)
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):
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)
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)
# #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)
#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 """
#fibonaci
def fibonaci(n):
if n==1:
return 0
elif n==2:
return 1
else:
return fibonaci(n-1)+fibonaci(n-2)
#factorial
def factorial(n):
"""
5*4*3*2*1
"""
if n==1:
return 1
else:
return n*factorial(n-1)
number=int(input("enter the number"))