Professional Documents
Culture Documents
Document 15
Document 15
# Program to convert the key list and values list to list of dictionaries.
ROLL NO – 02
PROGRAM-2
# Program to print the duplicates from a list of integers.
def Repeat(x):
_size = len(x)
repeated = []
for i in range(_size):
k=i+1
for j in range(k, _size):
if x[i] == x[j] and x[i] not in repeated:
repeated.append(x[i])
return repeated
def reverse(s):
str = ""
for i in s:
str = i + str
return str
s = "Geeksforgeeks"
SEC – A
ROLL NO – 02
PROGRAM-4
# Program to split list of string at the Kth character.
ROLL NO – 02
PROGRAM-5
# Program to add n to each element in a list of list of numbers.
my_list = [4, 5, 6, 3, 9]
print ("The original list is : " + str(my_list))
K=4
res = [x + K for x in my_list]
print ("The list after adding K to each element : " + str(res))
#OUTPUT-5
The original list is : [4, 5, 6, 3, 9]
The list after adding K to each element : [8, 9, 10, 7, 13]
CLASS - XII
SEC – A
ROLL NO – 02
PROGRAM-6
#Program to join the tuples inside a list if they have similar initial
elements.
List = [(1, 2), (1, 3), (1, 4), (5, 6), (7, 8)]
result = []
for sub in List:
if result and result[-1][0] == sub[0]:
result[-1].extend(sub[1:])
else:
result.append([ele for ele in sub])
result = list(map(tuple, result))
CLASS - XII
SEC – A
ROLL NO – 02
PROGRAM-7
# Program to extract the tuples in a list having n digit elements.
my_list = [(34, 56), (45, 6), (111, 90), (11, 35), (78, )]
K=2
print("The value of K has been initialized to" + "str(K)")
ROLL NO – 02
PROGRAM-8
# Program to sort tuples in a list by maximum elements in a
tuple.
def get_max_value(my_val):
return max(my_val)
my_list = [(4, 6, 8, 1), (13, 21, 42, 56), (7, 1, 9,0), (1, 2)]
print(“The list is : “)
print(my_list)
my_list.sort(key = get_max_value, reverse = True)
SEC – A
ROLL NO – 02
PROGRAM-10
# Program to convert tuple into list by adding a string after every
element.
K = "Pyt"
print("The value of K is :")
print(K)
def convert(l):
dic={}
for i in range(0,len(l),2):
dic[l[i]]=l[i+1]
return dic
ar=[1,'Delhi',2,'Kolkata',3,'Bangalore',4,'Noida']
print(convert(ar))
#OUTPUT-11
{1: 'Delhi', 2: 'Kolkata', 3: 'Bangalore', 4: 'Noida'}
print(dict_1 | dict_2)
#OUTPUT-12
{1: 'a', 2: 'c', 4: 'd'}
SEC – A
ROLL NO – 02
PROGRAM-15
#Program to remove the n’th character from a string.
if __name__ == '__main__':
str1 = input("Enter a String =")
n = int(input("Enter the n-th index ="))
ROLL NO – 02
PROGRAM-16
# Program to print the even length words from a string.
SEC – A
ROLL NO – 02
PROGRAM-17
# Program to convert the last half part of the string to uppercase and
other part to uppercase.
import math
string1 = 'transportation'
string1_len = len(string1)
part_a = ''
part_b = ''
new_part_a = part_a.upper()
print(changed_string)
#OUTPUT-17
TRANSPOrtation
def printRLE(s) :
i=0
count = 1
i += 1
count += 1
if i + 1 == len(s):
break
print(str(s[i]) + str(count),
i += 1
print()
if __name__ == "__main__" :
printRLE("GeeeEEKKKss")
printRLE("cccc0ddEEE")
#OUTPUT-18
G1 e3 E2 K3 s2
c4 O1 d2 E3
ROLL NO – 02