-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlist.py
More file actions
101 lines (57 loc) · 1.74 KB
/
list.py
File metadata and controls
101 lines (57 loc) · 1.74 KB
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
# List - collection, ordered, changeable, duplicate
# Waxaa ku dari kartaa data types
# fruit = ["Mango", "Apple", "Grape"]
# Index = number lagu garto oo ka bilowdo ZERO
# print(fruit[2])
# Slicing = Jar jarid
# fruit = ["Mango", "Apple", "Grape", "Banana", "Kiwi", "Melon", "Blackberry"]
# print(fruit[-4:])
# Change item in list
# fruit = ["Mango", "Banana", "Kiwi", "Melon", "Blackberry"]
# fruit[1] = "Apple"
# print(fruit)
# Loop Through list
# fruit = ["Mango", "Banana", "Kiwi", "Melon", "Blackberry"]
# for index, x in enumerate(fruit):
# print(index, x)
# Check if Item exists
# fruit = ["Mango", "Banana", "Kiwi", "Melon", "Blackberry"]
# if "Apple" in fruit:
# print("Yes, Banana is in list")
# else:
# print("No!")
# print(len(fruit))
# How to add item in List
# fruit = ["Mango", "Banana", "Kiwi", "Melon", "Blackberry"]
# fruit.append("Apple")
# fruit.insert(0, "apple")
# fruit2 = ["Apple", "Blueberry"]
# fruit.extend(fruit2)
# print(fruit + fruit2)
# How to remove from list
# fruit = ["Mango", "Banana", "Kiwi", "Melon", "Blackberry"]
# fruit.remove("Mango")
# removedItem = fruit.pop()
# print(removedItem)
# print(fruit)
# Reverse List
# fruit = ["Mango", "Banana", "Kiwi", "Melon", "Blackberry"]
# fruit.sort(reverse=True)
# fruit.reverse()
# print(fruit)
# Sorted Items
# fruit = ["Mango", "Banana", "Kiwi", "Melon", "Blackberry"]
# nums = [1, 5, 3, 2, 4, 6]
# nums.sort()
# sortedNumber = sorted(nums)
# print(sortedNumber)
# print(nums)
# Max, Min, Sum
# nums = [1, 5, 3, 2, 4, 6]
# print(sum(nums))
# Make list a string
# fruit = ["Mango", "Banana", "Kiwi", "Melon", "Blackberry"]
# fruit_str = " , ".join(fruit)
# fruit_list = fruit_str.split(" , ")
# fruit_list = list(fruit_str)
# print(fruit_list)