KEMBAR78
Python 02 | PDF
0% found this document useful (0 votes)
23 views10 pages

Python 02

The document discusses the use of lambda functions and the map function in programming. It provides examples of how to implement these functions to perform various operations like checking if a number is even, finding the square of integers, and manipulating strings. Additionally, it touches on comprehensions and their applications in Python.

Uploaded by

Rahul Ghosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views10 pages

Python 02

The document discusses the use of lambda functions and the map function in programming. It provides examples of how to implement these functions to perform various operations like checking if a number is even, finding the square of integers, and manipulating strings. Additionally, it touches on comprehensions and their applications in Python.

Uploaded by

Rahul Ghosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Lambda

’ lambda is a keynd hich is used fo ston lotme erinal


[yntax,
vo lanmbda ags! expreston
vaz (angs)

Exampk
n To ehuck shethn a membn is even orodel. s

Tauedoxs

Yonlr)
False

+
’ lambda is an anemymons fuHer
funton ahieh is mot haing
mame

’ T eall the funetion se ax going to stor the addhey bf


loumbdato avaiabk lo that e ean wse that to
callthe fuetion
1: WAP to fimd thu Sguae of Dh intgen mumb en girs
lambda

25
g2: wAP to eheck ahthun he -fiost vaue is gnetn then
Sewnd vahe Tt finst vaue is gneatethan Seod
Vaue, prnint "H else pnint "Bye'.th
neet Lambda ay b: H;'if ay b else 'Bye'

Bye'

given vahe is even else pint qube of-that munbn

temp C3)

WA to pnnt the vnue im nYose i the vae.is colle ios


a kihich cuppont imdaximg else print -the aue as it t.
Vn lambda coi: coll E:-7 + (eol) im's, tuplk, sf] else ale
O5: Wet to eheek uhathenhe give chasatn is
phyent intide
-the stning. It choratn is pryent-thes pnint ifs
initial index else pnint a it is.
e6: WAp to imd Cun of mimmm 3 nd maximum 5
umbus by poting aefauf vale
stning elte shbsta
exaely equal.
g8: HAP oeheek Akthe the aiveh k sting is Kuytnd
er mot.

Map
’tmap is a funetion shieh is used to penfon saeset of
operatlen fen ench and evary values prgent iide
the celleeten

pnint Cist(vm-nam))
MaihMthod

Or44

..ol

’tr map. type eagting is reqyuhal.


gL: WAP to find -the ength of ench ond evenq bmd
pnaszint ioeide astnig ohe
g2: hNAP to penfrm be los epenatieng
SBevH Rudna'

82: WAP to find ta fatonial of all he mumbng pogent in


cide the given homagenns iot colueten
g3: S = 'Gooal Byet
of = $'Groop': ged', eyE': byel}

’In map funehien, length ot inqut andotput coletie


shenld be cami to to ovasleme u ocbove pneblen,
4lfen is usede
nqune data foen
fls tunetton is used to get onythe inpufolkeien
th this case,fhe fumte whieh e ahe
false.
vN filn Gnam,<alletien)
pnint Cust(ns)
a= lambala men : mun 2 ==0
b- flhn (a, hange(!, leo))
nint (st (b)) hho'at

tP lonpnahivn
ameuaolleetisn by

’domgnahnting
’ Thiee typs of eophehniong au fhene.

cYÑ) bictiany eompnuhetlony

’T-is aphemenr o enuting a neks list oleeto


symtaa
allefin if <eondition
(hi) -thax is both ft and else tondtfon
v TSB ifKeonditioa} else f3E for
Exampla

jnint ([i4orn iin hange C, 1)])

ube of onyeven mwmbens.

3. inp =inf (imput ("Emfen nange: 1))

4. imnp inf (ngut("Fnfen nge: ) i a t


’WApto find squa fon even menby and cube fon
celds.

prt(nesn)
’WAP find eube of a mumbuny befaseeh fou nange
20fo 7e Omly if if is omultek of 5.
inep=in finputf

imp eval (impuut ())

insput= to, 'hai', 3l, st9'a':1, 'b': 2}7, *


rufput i, 3, 1, t,e]
inp [1o, 'hai, 3.t, stoi,a','s':z37
ngt=[en(itn) if type Citem) nof in Frt, conla,
{lon]else 1fn ifen in inp
’ imput= 'Rython is vay NAny eny'
oukput'ry thon', 6),("is, 2), (vamy u). ('vany'4)
("eany", )]
imp = Python is vny wy y!
nf=[Cikem, lenCitem) frn ifen in inp. splt o]
þrint (neutt)

output=|[Hagpy', i], Pl', ],yemA', ], [(aan,


2y HA to pntnt ((i,2), (13), Ct,4), (22),(93), (24), (3,2),
(3,3), (3, 4)]

2.

pruint (nent).
Set komnpnhenienothyon
’I+ is a pnecen of heating sef cotictin

Vz

WAP f fnd the squas of all even ad eube of at


odd mubeg betaReh the nange bo fo 20 anel st
pupu inthe form of sef aleefih)
hangefsoto)
ese uy*3 fn
um i nange (60
fm i im nage (2, mum):
atws alse
elseie

nint(nlt)

rint(ifriin oange(,ing a) if all( %i<eo fonj in


nange (2, imt (i**k D: 5)+ ))3)
’ input = 'abed abe abede
abede abcdef

You might also like