In this article List Examples in Python we give the information about Basic example of list, tuple, dictionary and set with output.

List Examples in Python :

1. Write a program to store five fruits in a list entered by the user.

Ans:-

fruits = []

f1 = input(“Enter the 1st fruit name: “)

fruits.append(f1)

f2 = input(“Enter the 2nd fruit name: “)

fruits.append(f2)

f3 = input(“Enter the 3rd fruit name: “)

fruits.append(f3)

f4 = input(“Enter the 4th fruit name: “)

fruits.append(f4)

print(fruits)

2. Write a program to accept marks of 4 students and display them in a sorted

Ans:-

marks = []

f1 = int(input(“Enter the 1st subject marks: “))

marks.append(f1)

f2 = int(input(“Enter the 2nd subject marks: “))

marks.append(f2)

f3 = int(input(“Enter the 3rd subject marks: “))

marks.append(f3)

f4 = int(input(“Enter the 4th subject marks: “))

marks.append(f4)

marks.sort()

print(marks)

3. Check that a tuple cannot be changed in python.

Ans:-

a=(55,”Sham”,1.8, 46,”Yash”)

a[4]=”Ganesh”

O/P: – TypeError: ‘tuple’ object does not support item assignment

4. Write a program to sum a list with 5 numbers.

 Ans:-

Compile Time:

l=[1,5,2,4,7]

print(sum(l))

Runtime:

l=[]

n1=(int(input(“Enter the 1st number: “)))

l.append(n1)

n2=(int(input(“Enter the 2nd number: “)))

l.append(n2)

n3=(int(input(“Enter the 3rd number: “)))

l.append(n3)

n4=(int(input(“Enter the 4th number: “)))

l.append(n4)

n5=(int(input(“Enter the 5th number: “)))

l.append(n5)

print(sum(l))

5. Write a program to count the number of zeros in the following tuple.

 A= (7, 8, 0, 8, 8, 0, 9, 9, 0)

 Ans.:-

A= (7, 8, 0, 8, 8, 0, 9, 9, 0)

n=A.count(0)

print(n)

6. Write a program to create a dictionary of Marathi words with values as their English translation. Provide user with an option to look it up!

words= {

“Aai”:”Mother”,

“Baba”: “Father”,

“Dada”: “Brother”,

“Kaka”: “Uncle”

}

word=input(“Enter the word you want meaning of : “)

print(words[word])

7. Write a program to show empty set, list, tuple and dict.

s=set()

print(type(s))

li=[]

print(type(li))

a=()

print(type(a))

p={}

print(type(p))

Some More: 

POP- Introduction to Programming Using ‘C’

DS – Data structure Using C

OOP – Object Oriented Programming 

Java Programming

DBMS – Database Management System

RDBMS – Relational Database Management System

Join Now: Data Warehousing and Data Mining 

Leave a Reply

Your email address will not be published. Required fields are marked *