0% found this document useful (0 votes)
5 views

"Enter Height" "Enter Base" "Area of Triangle": #Intersectionn List

This document contains Python code snippets demonstrating the use of lists, dictionaries, strings, and other data types. A variety of operations are performed including sorting lists, removing list elements, checking for substrings, and counting word frequencies.

Uploaded by

kittuuu241
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)
5 views

"Enter Height" "Enter Base" "Area of Triangle": #Intersectionn List

This document contains Python code snippets demonstrating the use of lists, dictionaries, strings, and other data types. A variety of operations are performed including sorting lists, removing list elements, checking for substrings, and counting word frequencies.

Uploaded by

kittuuu241
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/ 3

5/31/24, 10:09 AM Untitled2

In [2]: a=int(input("Enter height"))


b=int(input("Enter base"))
Are=1/2*b*a
print("area of triangle" ,Are)

area of triangle 75.0

In [7]: list1=[12,15,55,95,46,82,74,52]
list2=[65,45,2,85,78,32,48]

list3=sorted(list1+list2)
print(list3)

[2, 12, 15, 32, 45, 46, 48, 52, 55, 65, 74, 78, 82, 85, 95]

In [8]: list2=[65,45,2,85,78,32,48]
list2.append(100)
print(list2)

[65, 45, 2, 85, 78, 32, 48, 100]

In [12]: list2=[65,45,2,85,78,32,48]
list2.remove(2)
print(list2)

[65, 45, 85, 78, 32, 48]

In [13]: list2=[65,45,2,85,78,32,48]
list2.reverse()
print(list2)

[48, 32, 78, 85, 2, 45, 65]

In [19]: list1=[2, 12, 15, 32, 45, 46, 55, 55, 55, 65, 74, 78, 82, 82, 95]
list2=set(list1)
print(list2)

{32, 65, 2, 74, 12, 45, 46, 15, 78, 82, 55, 95}

In [26]: list1=[12,15,55,95,46,82,74,52]
list2=[12,45,52,85,78,32,46]

list3=set(list1)|set(list2)
print(list(list3))

[32, 74, 12, 45, 46, 15, 78, 82, 52, 85, 55, 95]

In [28]: #Intersectionn list


list1=[12,15,55,95,46,82,74,52]
list2=[12,45,52,85,78,32,46]
list3=[]
for i in list1:
if i in list2:
list3.append(i)

print(list3)

[12, 46, 52]

In [32]: a=["apple","banana","grapes","kiwi","apple","watermelon"]
b=input("Enter the element you want to remove ")
c=[]

file:///C:/Users/ASUS/Downloads/Untitled2.html 1/3
5/31/24, 10:09 AM Untitled2

oc=int(input("Enter the occurencee of the element "))


count=0
for i in a:
if(i==b):
count = count+1
if(count!=oc):
c.append(i)
else:
c.append(i)
if(count==0):
print("item not found")
else:
print(c)

['apple', 'banana', 'grapes', 'kiwi', 'watermelon']

In [38]: a="The cat sat on the mat and then the cat jumped off the mat"
word=a.split(" ")
b=input("Enter the word you want to find")
print(word)
count=0
for i in word:
if(i==b):
count = count +1
if(count == 0):
print("entered word is not found")
else:
print("Occurence of the word",b,"is",count,"times")

['The', 'cat', 'sat', 'on', 'the', 'mat', 'and', 'then', 'the', 'cat', 'jumped',
'off', 'the', 'mat']
Occurence of the word cat is 2 times

In [39]: a="The cat sat on the mat and then the cat jumped off the mat"
sub_str="The cat sat"

if sub_str in a:
print("Sub string is present")
else:
print("substring is not present")

Sub string is present

In [41]: name=["Raj","ketan","Ruturaj"]
marks=[95,85,98]
mapped_dict= dict(zip(name,marks))
print(mapped_dict)

{'Raj': 95, 'ketan': 85, 'Ruturaj': 98}

In [44]: b="The cat sat on the mat and then the cat jumped off the mat"
a={}
word=b.split(" ")
for i in word:
if i in a:
a[i]+=1
else:
a[i]=1
print(a)

file:///C:/Users/ASUS/Downloads/Untitled2.html 2/3
5/31/24, 10:09 AM Untitled2

{'The': 1, 'cat': 2, 'sat': 1, 'on': 1, 'the': 3, 'mat': 2, 'and': 1, 'then': 1,


'jumped': 1, 'off': 1}

In [ ]:

file:///C:/Users/ASUS/Downloads/Untitled2.html 3/3

You might also like