Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # list_manip.py
- L = ['yellow', 'red', 'blue', 'green', 'black']
- print L, 'is the example list'
- print 'List is of', len(L), 'colors'
- print sorted(L), 'is in alphabetical order'
- append_color = 'purple'
- L.append(append_color)
- print L
- print 'Added', append_color, 'to the end of the list'
- add_color = ['gold']*5
- L += add_color
- print L
- print 'Added a list of', add_color, 'to the list'
- number_of_gold = L.count('gold')
- print 'There are', number_of_gold, 'instances of gold in the list'
- L.remove('gold')
- print 'The first of instance of gold has been removed'
- L = [new_L for new_L in L if new_L != ('gold')]
- print L
- print 'Each of the instances of gold has been removed'
- insert_color = 'white'
- L.insert(3, insert_color)
- print L
- print 'Inserted', insert_color, 'as forth* item in the list (0,1,2,*3)'
- popped_color = L.pop()
- print L
- print 'pop() removed last item, which is', popped_color, ', from the list'
- popped_color = L.pop(2)
- print L
- print 'pop(2) removed', popped_color, 'from the list'
- L.reverse()
- print L
- print 'List has been reversed'
- if 'red' in L:
- print 'list contains red'
- print
- for item in L:
- print item
- print
- import random
- R = list(range(25))
- L += R
- random.shuffle(L)
- print L
- L = list(set(L) - set(R))
- print
- print L
- print 'The items of numbers has been removed from the list of colors'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement