-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7. List Functions.py
63 lines (44 loc) · 902 Bytes
/
7. 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
l = ["Jim", "Mike", "Toby", "Toby", "Kevin", "Karen"]
# append list on the end side
l.append("Creed")
# insert at an index
l.insert(1, "Kelly")
# get the index
l.index("Mike")
# count a specific element
l.count("Toby")
# ----------
# pop the last element or index
l.pop()
l.pop(3)
# remove
l.remove("Karen")
# del keyword removes the specified index
del l[1]
# The del keyword can also delete the list completely
# del l
# clear the list
l.clear()
# -----------
# Sort case sensitive
l.sort()
# Sort Descending
l.sort(reverse = True)
# case insensitive
l.sort(key = str.lower)
# reverse the order
l.reverse()
# -------------
# make copy
l.copy()
# make copy via list()
newlist = list(l)
# -------------
# Join list
list3 = list1 + list2
# extend list with Any Iterable
thislist = ["apple", "banana", "cherry"]
thistuple = ("kiwi", "orange")
thislist.extend(thistuple)
# length
len(l)