-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path019.Creating_Lists.py
83 lines (67 loc) · 1.62 KB
/
019.Creating_Lists.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
empty_lists = []
even = [2,4,6,8]
odd = [1,3,5,7,9]
numbers = even + odd
print(numbers)
sorted_numbers = sorted(numbers)
print(sorted_numbers)
print(numbers)
digits = sorted("4856379120")
print(digits)
#copy a list
#more_numbers = list(numbers)
#more_numbers = numbers[:]
more_numbers = numbers.copy()
print(more_numbers)
print(more_numbers is numbers)
computer_parts = ["computer","monitor","keyboard","mouse","mouse mat"]
print(computer_parts)
#replacing
computer_parts[3] = "trackpad"
print(computer_parts)
#replacing slices
computer_parts[3:] = ["trackball"]
print(computer_parts)
#deleting items
data = [1,2,3,4,5,6,7,8,9,10]
del data[0:2]
print(data)
del data[5:]
print(data)
data=[1,4,5,100,105,110,120,130,140,150,170,199,200,201,210,250,299]
print(data)
min_valid = 100
max_valid = 200
#process the low value in list
stop = 0
for index,value in enumerate(data):
if value >= min_valid:
stop = index
break
print(stop)
del data[:stop]
print(data)
#procezs the high value in list
start = 0
for index in range(len(data) -1,-1,-1):
#print(index)
if data[index] <= max_valid:
start = index + 1
break
print(start)
del data[start:]
print(data)
#reverse reomving of data
print()
data = [104,101,4,105,308,103,5,107,100,306,106,102,108]
# for index in range(len(data)-1,-1,-1):
# if data[index]<min_valid or data[index]>max_valid:
# print(index,data)
# del data[index]
# print(data)
top_index = len(data)-1
for index,value in enumerate(reversed(data)):
if value<min_valid or value>max_valid:
print(top_index-index,value)
del data[top_index-index]
print(data)