# Addition of List Elements.
# Addition of List Elements.
lst1 = [1,2,3,4,5,85]
addition = sum(lst1)
#GROUP 1ST……
Lst1 = [1,2,3,4,5]
Multiplication = 1
For x in lst1:
Multiplication *= x
Lst1 = [1,2,3,4,5]
Max = max(Lst1)
print(“Maximum:”,Max)
Lst1 = [1,2,3,4,5]
Min = min(Lst1)
print(“Minimum:”,Min)
4.Count number of strings where string length is two or more and the first and last character are
same..
count = 0
for i in lst1:
count += 1
print(i)
print(count)
lst1 = [1,2,3,4,5,4,6,3,7,8]
uncommon = set(lst1)
lst1 = []
if len(lst1) == 0:
print(“empty list!”)
else:
for i in lst1:
print(i)
lst2 = [9,8,7,6,3,5,4]
copied_list = lst2.copy()
print(copied_list)
lst1 = [1,2,3,4,5,6,7,8,9]
for i in lst1:
if (i%2 != 0):
print(i)
9.Checking common item from two lists accepted as input from user..
lst1 = lst1.split(‘,’)
lst2 = lst2.split(‘,’)
if len(common) == 0:
print(“No common”)
else:
print(common)
lst1 = [1,2,3,4,5,6,7,8]
print(lst1)
lst1.pop(0)
print(lst1)
lst1.pop(4)
print(lst1)
lst1.pop(5)
print(lst1)
________________________________________
#GROUP 2ND………
tpl = (1,2,3,4,"Sayantani",6.3)
print(tpl)
reversed_tuple = tpl[::-1]
print(reversed_tuple)
tpl = (1,2,3,4,20,6.3)
print(tpl)
print(tpl.index(20))
Tpl = (50)
print(Tpl)
tpl = (1,2,3,4,5,6,7,8,9)
print(var1)
print(var2)
print(var3)
print(var4)
print(remaining)
tpl1 = (1,2,3,4)
tpl2 = (9,8,7,6)
temp = ()
temp = tpl1
tpl1 = tpl2
tpl2 = temp
print(tpl1)
print(tpl2)
# Or
tpl1 = (1,2,3,4)
tpl2 = (9,8,7,6)
print(tpl1)
print(tpl2)
tpl1 = (0,1,2,3,4)
tpl2 = (9,8,7,6,5)
print(Mixed_tpl)
tpl1 = (0,1,2,3,4)
print(New_tuple)
tpl = (10,20,50,30,40,50)
cnt = tpl.count(50)
print(cnt)
tpl = (9,9,9,9,9)
flag = False
for i in tpl:
if (i == tpl[0]):
flag = True
else:
flag = False
if flag == True:
else:
________________________________________
#GROUP 3RD………
lst1 = [1,2,3,4,5]
lst2 = [“A”,”B”,”C”,”D”,”E”]
dict1 = dict(zip(lst1,lst2))
print(dict1)
dict1 = {1:”A”,2:”B”,3:”C”,4:”D”,5:”E”}
dict2 = {6:”F”,7:”G”,8:”H”,9:”I”}
dict1.update(dict2)
print(dict1)
dict1 = {“English”:94,”Physics”:91,”Chemistry”:89,”Biology”:96,”History”:92}
print(dict1[“History])
dict1 = {“A”,”B”,”C”}
initialized = dict.fromkeys(dict1,0)
print(initialized)
mydict = {“roll”:63,”name”:”Vaibhav”,”marks”:35,”branch”:”com”}
keys = [“roll”,”name”]
print(dict2)
dict1 = {1:”A”,2:”B”,3:”C”}
removable = (2)
del dict1[removable]
print(dict1)
dict1 = {1:”A”,2:”B”,3:”C”}
removables = [1,3]
for key in removables:
if key in dict1:
print(dict1)
dict1 = {1:”A”,2:”B”,3:”C”}
keys = [3,5,2,1,6,8]
if value in dict1:
print(“Exist”)
else:
dict1 = {“key”:”value”}
new = dict1.pop(“key”)
print(dict1)
dict1 = {“a”:1,”b”:2,”c”:3,”d”:4}
minimum = min(dict1.items())
print(minimum)
________________________________________
GROUP 4TH………
1.Create string made up of first, middle and last characters..
str1 = “Vaibhav”
print(“Extracted string:”,str_comb)
str1 = “Vaibhav”
print(“Extracted string:”,modified_str)
str1 = “Vaibhav”
string_to_append = “ana”
middle = len(str1)//2
print(appended_str)
4. Create string made up of first, middle and last characters of input string..
print(“Extracted string:”,str_comb)
str1 = “ajdhePraejoAksSMskbhavnejwjwaliVai”
print(str2)
6.Count all letters, digits and special symbols from a given string..
str1 = “ajaiiee6e_an@vaiket:)ali3m!”
l_count = 0
ss_count = 0
d_count = 0
if element.isalpha():
l_count += 1
elif element.isdigit():
d_count += 1
else:
ss_count += 1
print(l_count)
print(d_count)
print(ss_count)
#Extract substring from given list of strings which has been ended with letter ‘s’..
strings = [“Jarvis”,”Friday”,”Alexis”,”Frances”,”Paris”,”Thomas”]
if items.endswith(‘s’):
string_sliced = items[:-1]
print(string_sliced)
67.String character balance test..
flag = False
if len(str1)==len(str2):
for I in str1:
if I in str2:
flag = True
else:
flag = False
if flag == True:
else:
str1 = string_input.lower()
print(str1)
occ_count = 0
if substring in string_input:
occ_count += 1
print(occ_count)
str1 = list(string_input.lower())
occ_count = {}
for substring in str1:
if substring in occ_count:
occ_count[substring] += 1
else:
occ_count[substring] = 1
print(occ_count)
summation = 0
average = 0
no_of_digits = 0
if string_input.isdigit() == True:
for i in string_input:
no_of_digits += 1
summation += int(i)
average = summation/no_of_digits
print(summation)
print(average)
_________________________________________
#GROUP 5TH…………
def add(x,y,z=0):
z=x+y
return z
result = add(10,20)
print("Addition:",result)
def funct1(*args):
addition = 0
for i in args:
addition += i
return addition
print("Addition:",funct1(1,2,3,4,5))
def func1(x,y,z):
return x,y,z
print(func1(1,2,3))
def func1(a,b,default=48):
return (a+b+default)
print(func1(4,2))
def outer_f(a,b):
def inner_f(addition=0):
addition = a + b
return addition
print(inner_f())
outer_f(6,48)
if num == 0 or num == 1:
return 1
else:
print(factorial(5))
7.Assign different name to function and call it through the new name..
def demo():
print("Demo function")
new_demo = demo
print(new_demo())
def even_no(start,end):
e_lst = []
if (num%2) == 0:
e_lst.append(num)
print(e_lst)
even_no(4,30)
def largest(lst):
maximum = max(lst)
return maximum
lst = [20,48,26,45]
print(largest(lst))
________________________________________
GROUP 6TH………
print(myset)
print(myset1.intersection(myset2))
print(myset1.union (myset2))
4.Update the first set with elements that don’t exist in second set
Myset1 = {1, 2, 3, 4, 5}
Myset2 = {4, 5, 6, 7, 8}
Myset1.update(myset2 -myset1)
Print(myset1)
myset1 = {1, 2, 3, 4, 5}
items_to_remove = {4, 5}
myset1.difference_update(items_to_remove)
print(myset1)
A = {1, 2, 3, 4, 5}
B = {4, 5, 6, 7, 8}
print(A.union(B))
myset1 = {1, 2, 3, 4, 5}
myset2 = {9, 8, 7, 6, 5}
myset3 = myset1.intersection(myset2)
if (myset1.intersection(myset2)) != {}:
print(“Common items:”,myset3)
myset1 = {1, 2, 3, 4, 5, 6}
myset2 = {6, 7, 8, 9, 0, 1}
myset1.update(myset2)
print(myset1)
9.Remove items from set1 that are not common in both set1 and set2
myset1 = {1, 2, 3, 4, 5, 6}
myset2 = {6, 7, 8, 9, 0, 1}
myset2.difference(myset1)
print(myset2)
_______*******_______*__*_*_**__*_*_*_*_*_*_**__*_*_*__*_*