Posts

Showing posts from July, 2021

Enumerate Functions

  lst1=[ 'kartik' , 'aman' , 'ramdev' , 'raju' ] for index , item in enumerate (lst1): #Bhiya enumerate function index or items dono ko iterate karta hai if index% 2 != 0 : print (item)

MAP, FILTER, REDUCE Functions

print ( "----------------------------MAP-----------------------------------" ) def sq (a): return a*a def cube (a): return a*a*a ks=[sq , cube] for i in range ( 1 , 5 + 1 ): val1= list ( map (( lambda x:x(i)) , ks)) print (val1) print ( "---------------------------FILTER-----------------------------------" ) lst=[ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] def is_greater_5 (p): return p> 5 print ( list ( filter (is_greater_5 , lst))) print ( "---------------------------REDUCE-----------------------------------" ) from functools import reduce lst=[ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] k=reduce(( lambda x , y:x+y) , lst) print (k)

*Args and **Kwargs

  def Fun_Fact (normal , *args , **kwargs): print (normal) for items in args: print (items) for key , value in kwargs.items(): print (key , value) a= "I am normal " b=[ "kartik" , "ayush" , 'aman' , "Piyush" , "Meetha" , "Rohit" ] c={ "kartik" : "Photoshop" , "Aman" : "Driver" , "jay" : "cook" } Fun_Fact(a , *b , **c)

Take Multiple Input in one String

  n= list ( map ( int , input ( "Enter number " ).split( ',' ))) print ( f'The Sum of Given Number = { sum (n) } ' )

Factorial using iterative method and Recursive method

  Recursive Method def Recursive (n): if n== 1 : return 1 else : return n*Recursive(n- 1 ) n= int ( input ( "Enter a number " )) print (Recursive(n)) Iterative Method def iterative (n): fac= 1 for i in range (n): fac=fac*(i+ 1 ) return fac

Replace text in files

  with open ( "Non.txt" ) as f: c=f.read() c=c.replace( 'gandu' , '#$$$%#' ) with open ( "Non.txt" , 'w' ) as f: f.write(c)

Health Management System Project

Image
  #log for kartik import datetime def gettime (): return datetime.datetime.now() def LogValue (a): if (a== 1 ): c= int ( input ( "1 for food and 2 for excercise \t " )) if (c== 1 ): name= int ( input ( "1 for ayush 2 for jay 3 for kartik \t " )) if (name== 1 ): food= input ( "Aysuh write your food \n " ) with open ( "ayush.txt" , 'a' ) as f: f.write( str ([ str (gettime())])+ ": " +food+ " \n " ) print ( "Successfuly Writen" ) elif (name== 2 ): food= input ( "Jay write your food \t " ) with open ( "Jay.txt" , 'a' ) as f: f.write( str ([ str (gettime())])+ ": " +food+ " \n " ) print ( "Successfuly Writen" ) elif (name== 3 ): food...

List Comprehension

 List Comprehension  1 Normal writing Code  lst=[ 1 , 2 , 4 , 5 , 7 , 9 ] for i in range (lst[ 0 ] , lst[- 1 ]+ 1 ): #ye sab apn list comprehension se kr skte hai if i not in lst: print (i) 2 YE list comprehension ke saath def FindMissing (lst): return [i for i in range (lst[ 0 ] , lst[- 1 ]+ 1 ) if i not in lst ] lst=[ 1 , 2 , 4 , 5 , 6 , 8 , 9 , 11 , 14 , 16 ] print ( f"These are Missing Numbers = { FindMissing(lst) } " )           Source--------- https://youtu.be/m3yd3N57nVY