Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Introduction To Python & R

Name :- Chinmay Mokal

Question 1

list1=["Car",12,"Bike",5,"Aircraft",10,30,"Boat",53,"Railway"]

list1

['Car', 12, 'Bike', 5, 'Aircraft', 10, 30, 'Boat', 53, 'Railway']

print(len(list1))

10

list1.reverse() 

print (list1)

['Railway', 53, 'Boat', 30, 10, 'Aircraft', 5, 'Bike', 12, 'Car']

for i in list1[0:3]:{

print(type(i))

<class 'str'>

<class 'int'>

<class 'str'>

list1.clear() 

print (list1)

[]

Question 2

string="""#### KC COLLEGE PROVIDES VARIOUS COURES LIKE Msc In $STATS, Msc IN $CHEMISTRY,Msc IN $BIOTECHNOLOGY,BACHELORS IN $COMPUTER SCIENCE WITH ALL NECESSARY EQUIPMENTS AND TECHNICAL LABS REQUIRED FOR PRACTICALS #######"""

string1=string.strip("#")
string1

' KC COLLEGE PROVIDES VARIOUS COURES LIKE Msc In $STATS, Msc IN $CHEMISTRY,Msc IN $BIOTECHNOLOGY,BACHELORS IN $COMPUTER SCIENCE WITH ALL NECESSARY EQUIPMENTS AND TECHNICAL LABS REQUIRED FOR PRACTICALS '

string2=string1.replace("$"," ") 

string2

' KC COLLEGE PROVIDES VARIOUS COURES LIKE Msc In STATS, Msc IN CHEMISTRY,Msc IN BIOTECHNOLOGY,BACHELORS IN COMPUTER SCIENCE WITH ALL NECESSARY EQUIPMENTS AND TECHNICAL LABS REQUIRED FOR PRACTICALS '

string3=string2.lower()

string3

' kc college provides various coures like msc in stats, msc in chemistry,msc in biotechnology,bachelors in computer science with all necessary equipments and technical labs required for practicals '

wordcount=string3.count("msc") 

wordcount

splittext=string3.split(",")

splittext

[' kc college provides various coures like msc in stats',

' msc in chemistry',

'msc in biotechnology',

'bachelors in computer science with all necessary equipments and technical labs required for practicals ']

stringpartition=string3.partition("msc")

stringpartition

(' kc college provides various coures like ',

'msc',

' in stats, msc in chemistry,msc in biotechnology,bachelors in computer science with all necessary equipments and technical labs required for practicals ')

Question 3

cardata={"Fiat":5000,"Ford":10000,"Tesla":8000,"Tata":7000,"Nisan":9000}

cardata

{'Fiat': 5000, 'Ford': 10000, 'Nisan': 9000, 'Tata': 7000, 'Tesla': 8000}

for key in cardata:

  print([key])

['Fiat']

['Ford']

['Tesla']

['Tata']

['Nisan']

cardata.keys()

dict_keys(['Fiat', 'Ford', 'Tesla', 'Tata', 'Nisan'])

for val in cardata:

  print(cardata[val])

5000

10000
8000

7000

9000

cardata.values()

dict_values([5000, 10000, 8000, 7000, 9000])

list1=(cardata.keys())

list1

dict_keys(['Fiat', 'Ford', 'Tesla', 'Tata', 'Nisan'])

list2=(cardata.values())

list2

dict_values([5000, 10000, 8000, 7000, 9000])

cardata.update({"Ferrari":12000})

cardata

{'Ferrari': 12000,

'Fiat': 5000,

'Ford': 10000,

'Nisan': 9000,

'Tata': 7000,

'Tesla': 8000}

cardata.clear() 

cardata

{}

You might also like