-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlist_methods.py
More file actions
92 lines (65 loc) · 1.55 KB
/
Copy pathlist_methods.py
File metadata and controls
92 lines (65 loc) · 1.55 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
# adding elements to the list
# append
# names = ['apple', 'google', 'yahoo', 'amazon', 'microsoft']
# names.append("instagram")
# print(names)
# names.append([1, 2, 3])
# print(names)
# extend
# names = ['apple', 'google', 'yahoo', 'amazon', 'microsoft']
# names.extend("instagram")
# print(names)
# names.extend([1, 2, 3])
# print(names)
# insert
# names = ['apple', 'google', 'yahoo', 'amazon', 'microsoft']
# names.insert(3, "facebook")
# print(names)
# removing elements from a list
# names = ['apple', 'google', 'yahoo', 'amazon', 'microsoft']
# pop
# print(names.pop(2))
# print(names)
# print(names.pop())
# print(names)
# names.pop(10)
# remove
# names.remove("amazon")
# print(names)
# names.remove("flipkart")
# print(names)
# del
# names = ['apple', 'google', 'yahoo', 'amazon', 'microsoft']
# del names[2:]
# print(names)
# copy
# names = ['apple', 'google', ['yahoo', 'amazon'], 'microsoft']
# print(id(names))
# print(id(names[2]))
# list_ = names[::]
# print(id(list_))
# l = names.copy()
# print(list_)
# print(id(l))
# print(id(l[2]))
# sorting a list
names = ['apple', 'google', 'yahoo', 'amazon', 'microsoft']
# names.sort() # ASCII
# print(names)
# names.sort(key=len)
# print(names)
# names.sort(reverse=True)
# print(names)
# using split and join
s = "hai how are you"
l = s.split()
print(l)
s1 = " ".join(l)
print(s1)
# using list constructor and join
s = "hai how are you"
l = list(s)
print(l)
# s2 = "".join(l)
s2 = str().join(l)
print(s2)