Python Program-Set 4(P31-P40)

How will you remove the duplicate element of the list?
list12 = [10,20,20,3,55]  
list21 = []  
for i in list12:  
    if i not in list21:  
        list21.append(i)  
print(list21) 
Write the program to find the lists consist of at least one common element.
list1 = [1,2,3]  
list2 = [7,8,9]  
for x in list1:  
    for y in list2:  
        if x == y:  
            print("The common is:",x) 
Write a program to create a list of 6 odd integers.
Replace the fourth element with a list of 3 even integers.
After that perform Flatten, sort and
print the list.

x = [1, 3, 5, 7, 9,11]
y = [2, 4, 6]
x[3] = y
print(x)
x = x[:3] + [*y] + x[4:]
print(x) 
x.sort()
 print(x)

Output

[1, 3, 5,[2, 4, 6], 9,11]

[1, 3, 5,2, 4, 6, 9,11]

[1, 2, 3, 4,5, 6,  9,11]
A list contains 10 integers generated randomly. Give any input and show its position in the list.
import random
list1 = []
for k in range(10):
  n = random.randint(0, 40)
  list1.append(n)
print(list1)

num1 = int(input('Enter number:'))
count = 0
for i in range(len(list1)):
  if list1[i] == num1:
     print('Number found at position:', i)
Suppose a list has 10 numbers. Write a program to removes duplicates.
list1 = [1, 2, 3, 4, 3, 4, 5, 10, 20, 68]
print('list: ', list1)
final_list1=[]
for num in list1:
  if num not in final_list1:
     final_list1.append(num)

list1 = final_list1
print('List after removing duplicates:', list1)
In Class 6, some of the students got negative marks and some students got positive marks. How will you create lists of positive and negative Numbers separately?

list11 = [10, -19, -26, -40, -70,-10, 20, 30, 14, 15]
list12 = []
list13 = []
count, ncount = 0, 0
for x in list11:
  if x >= 0:
     list12.append(x)
  else:
     list13.append(x)

print(' list:', list11)
print('Positive Numbers list:', list12)
print('Negative Numbers list:', list13)
How will you convert list into uppercase?
list1 = ['abc', 'def']
for i, item in exerate(list1):
  list1[i] = item.upper()
print(list1)
Output
[‘ABC’, ‘DEF’]
Can we create empty list object?
list=[]
print(list)
Explain split() function.
x="Learning java"
l=x.split()
print(l)

['Learning', 'java',]
How List is mutable?Explain any example.
1) x=[10,20]
2) print(n)
3) n[1]=777
4) print(n)
--[10, 777]