0% found this document useful (0 votes)
24 views12 pages

1 SC

This document contains 13 programs written in Python. The programs demonstrate working with various Python data types like lists, tuples, sets and dictionaries. The programs perform operations like finding the length and counts in a list, accessing elements in tuples by index, finding maximum/minimum values in sets, sorting dictionaries by values etc. Screenshots of input/output are provided for each program.

Uploaded by

SABYASACHI SAHOO
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)
24 views12 pages

1 SC

This document contains 13 programs written in Python. The programs demonstrate working with various Python data types like lists, tuples, sets and dictionaries. The programs perform operations like finding the length and counts in a list, accessing elements in tuples by index, finding maximum/minimum values in sets, sorting dictionaries by values etc. Screenshots of input/output are provided for each program.

Uploaded by

SABYASACHI SAHOO
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/ 12

T&T Lab.

(CS-3096), Spring 2023

Tool & Technique Laboratory (T&T Lab.)


[CS-3096]
Individual Work
Lab. No: 4 , Date: 17/2/2023 , Day:FRIDAY
Topic: LIST-TUPLE-SET-DICT
Roll Number: 2006189 Branch/Section: IT3
Name in Capital: SABYASACHI SAHOO

Program No: 4.1

Program Title:
WAP to create a list and finds its length

Input/Output Screenshots:

Source code

demoList = ["Python", 1, "JavaScript", True, "HTML", "CSS", 22]

sizeOfDemoList = len(demoList)

Page
T&T Lab.(CS-3096), Spring 2023

print("The length of the list using the len() method is: " + str(sizeOfDemoList))

Program No: 4.2

Program Title:
WAP to count even and odd numbers in the list

Input/Output Screenshots:

Source code

list1 = [10, 21, 45, 66, 93]

even_count, odd_count = 0, 0

for num in list1:

if num % 2 == 0:
even_count += 1

else:
odd_count += 1
Page
T&T Lab.(CS-3096), Spring 2023

print("Even numbers in the list: ", even_count)


print("Odd numbers in the list: ", odd_count)

Program No: 4.3

Program Title:

WAP to find the sum of the digits in the list


Input/Output Screenshots:

Source code
test_list = [12, 67, 98, 34]

print("The original list is : " + str(test_list))

res = []
for ele in test_list:
sum = 0
for digit in str(ele):
sum += int(digit)
res.append(sum)

Page
T&T Lab.(CS-3096), Spring 2023

print ("List Integer Summation : " + str(res))

Program No: 4.4

Program Title:
WAP to create a tuple and find its length.

Input/Output Screenshots:

Source code

thistuple = ("SABYA", "2006189", "IT")


print(thistuple)
print(len(thistuple))

Program No: 4.5

Program Title:

WAP to create a tuple and find the index of the 3rd and 4th element
Page
T&T Lab.(CS-3096), Spring 2023

Input/Output Screenshots:

Source code
Tuple_data = (0, 1, 2, 3, 2, 3, 1, 3, 2)
# getting the index of 3
res = Tuple_data.index(3)
print('First occurrence of 1 is', res)
# getting the index of 3 after 4th
# index
res = Tuple_data.index(3, 4)
print('First occurrence of 1 after 4th index is:', res)

Program No: 4.6


Program Title:
WAP to get the 4th element from the last element in the tuple

Input/Output Screenshots:

Page
T&T Lab.(CS-3096), Spring 2023

Source code
tuplex = ("w", 3, "r", "e", "s", "o", "u", "r", "c", "e")
print(tuplex)
#Get item (4th element)of the tuple by index
item = tuplex[3]
print(item)
#Get item (4th element from last)by index negative
item1 = tuplex[-4]
print(item1)

Program No: 4.7

Program Title:
WAP to get the repeated items in the tuple

Input/Output Screenshots:

Page
T&T Lab.(CS-3096), Spring 2023

Source code
tuplex = 2, 4, 5, 6, 2, 3, 4, 4, 7
print(tuplex)
#return the number of times it appears in the tuple.
count = tuplex.count(4)
print(count)

Program No: 4.8

Program Title:
WAP to find the maximum and minimum element from the set

Input/Output Screenshots:

Page
T&T Lab.(CS-3096), Spring 2023

Source code
number_set = {5, 10, 3, 15, 2, 20}
print("Original set elements:", number_set)
print("\nMaximum value of the set:",max(number_set))
print("\nMinimum value of the set:",min(number_set))

Program No: 4.9

Program Title:
WAP to find the square of each elements of the set

Input/Output Screenshots:

Page
T&T Lab.(CS-3096), Spring 2023

Source code
num = {2,4,6,8,9,10}
res_set = set()
for x in num:
res_set.add(x*x)
print("Updated copy of set1:", res_set)

Program No: 4.10

Program Title:
WAP to find the unique elements and its count in the set

Input/Output Screenshots:

Source code

def word_count(words):
Page
T&T Lab.(CS-3096), Spring 2023

word_set = set(words)
word_counts = {}
for word in word_set:
word_counts[word] = words.count(word)
return word_counts

words = ['Red', 'Orange', 'Red', 'Blue', 'Red', 'Orange', 'Green', 'Yellow', 'Green']

Program No: 4.11

Program Title:
WAP script to sort (ascending and descending) a dictionary by value

Input/Output Screenshots:

Source code

import operator
d = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
print('Original dictionary : ',d)
sorted_d = sorted(d.items(), key=operator.itemgetter(1))
print('Dictionary in ascending order by value : ',sorted_d)
sorted_d = dict( sorted(d.items(), key=operator.itemgetter(1),reverse=True))
Page
T&T Lab.(CS-3096), Spring 2023

print('Dictionary in descending order by value : ',sorted_d)


Program No: 4.12

Program Title:
WAP to add a key to a dictionary.

Input/Output Screenshots:

Source code
d = {0:10, 1:20}
print(d)
d.update({2:30})
print(d)

Program No: 4.13

Program Title:
WAP to to concatenate dictionaries to find the new one

Page
T&T Lab.(CS-3096), Spring 2023

Input/Output Screenshots:

Source code
dic1={1:10, 2:20}
dic2={3:30, 4:40}
dic3={5:50,6:60}
dic4 = {}
for d in (dic1, dic2, dic3): dic4.update(d)
print(dic4)

Page

You might also like