-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlists.py
45 lines (31 loc) · 770 Bytes
/
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
print """
working with python lists now
"""
list = ['a','b','c']
print list
print list[0]
# same as list[0]
print list[:1][0]
# repeat the list five times over
print list*(3+2)
# append first item to last of the list
print list + list[:1]
print list + list[2:]
print "Shallow copy of list "
print list[:]
print "Insert a list at its own beginning"
list[:0] = list
print list
print "Iteratively Clear a list, removing the first item from the list each time"
copy = list[:]
# this is true as long as copy is not empty
while copy:
copy[:1]=[]
print copy
print " length = %s" % len(copy)
print "Iteratively Clear a list, removing the last item from the list each time"
copy = list[:]
while copy:
copy[-1:]=[]
print copy
print " length = ", len(copy)