-
Notifications
You must be signed in to change notification settings - Fork 0
/
3. List Functions.py
109 lines (83 loc) · 1.75 KB
/
3. List Functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# LIST
# Reading list using for loop
student = [16, "PFSD", 2200031954, 16, 2.30, "Hero"]
for i in student:
# this area id=s called indentation in for loop
print(i, "type is", type(i))
print(student)
print(type(student))
print()
kk = [12, "khowshikk", 34, 2.30, 23]
print("integers,")
for i in kk:
if type(i) == int:
print(i)
print()
print("floats,")
for i in kk:
if type(i) == float:
print(i)
print()
print("strings,")
for i in kk:
if type(i) == str:
print(i)
print()
# appending list
ll = [12, "khowshikk", 10.12, 2004, 12.2004, "sharma", "love u dad", "20.04.2020"]
l1 = []
l2 = []
for x in ll:
if type(x) == str:
l1.append(x)
if type(x) == float:
l2.append(x)
print("Previous list,\nll =", ll)
print("New list,\nl1 =", l1, "\nl2 =", l2)
# Adding 2 list
l = []
l = l1 + l2
print("Combination of 2 newlists,\nl =", l)
for i in range(len(l) - 1, -1, -1):
print(l[i])
# Reversing list
print("Reverse printing of a list,\n l =", l[::-1])
print()
# Reading list elements using keyboard
print("Enter the integer values for list k,")
k = []
n = 5
for i in range(n):
a = input()
k.append(a)
print("\nNew list,k reading using keyboard,\nk =", k)
student = [16, "PFSD", 2200031954, 16, 2.30, "Hero"]
f=student.copy()
print(f)
f1=student.extend(student)
#scanning list
ll=list(input().split())
print(ll)
l = [1, 2, 3, 4, 5, 6, 3, 3, 3, 7, 8, 9]
print(l)
print(l.count(3))
l[1:3] = [10, 11]
print(l)
l.append(15)
print(l)
l.insert(5, 20)
print(l)
l.sort()
print(l)
k = [21, 22, 23]
print(l)
l.extend(k)
print(l)
l.remove(15)
print(l)
l.reverse()
print(l)
l.pop()
print(l)
l.clear()
print(l)