Python Practicals Grade Xii
Python Practicals Grade Xii
PRACTICALS
Kushagra Parijat Lahir
Grade XII
Science
Program to find a Factorial of A
Number
# Swapping
temp = newList[0]
newList[0] = newList[size - 1]
newList[size - 1] = temp
return newList
# Driver code
newList = [12, 35, 9, 56, 24]
print(swapList(newList))
Check if element exists in list in
Python
lst=[ 1, 6, 3, 5, 3, 4 ]
#checking if element 7 is present
# in the given list or not
i=7
if i in lst:
("exist") else:
("not exist")
Python Cloning or Copying
a List
# Python program to copy or
clone a list
# Using the Slice Operator
def Cloning(li1):
li_copy = li1[:]
return li_copy
# Driver Code
li1 = [4, 8, 2, 10, 15, 18]
li2 = Cloning(li1)
print("Original List:", li1)
print("After Cloning:", li2)
Program for removing i-th
character from a string
# Python3 program for removing i-th
# indexed character from a string
# Driver Code
if __name__ == '__main__':
string = "geeksFORgeeks"
myKeys = list(myDict.keys())
myKeys.sort()
sorted_dict = {i: myDict[i] for i in
myKeys}
print(sorted_dict)
Ways to remove a key from
Dictionary
# Initializing dictionary
test_dict = {"Arushi": 22, "Mani": 21,
"Haritha": 21}
def remov_duplicates(input):
# Driver program
if __name__ == "__main__":
input = 'Python is great and Java is also great'
remov_duplicates(input)