Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- color = ['ref','green','white','black','pink','yellow'] ## is a python list object
- coloor = [x for i,x in enumerate(color) if i not in (0,4,5)]
- ## here using different variable coloor because otherwise the original list color will be overwrite.
- """
- ## 2nd line is using Python List Comprehensions technique which is the short form of the following code
- coloor = []
- for i,x in enumerate(color):
- ... if i not in (0,4,5): ## this condition is checking i is not in position 0, 4, 5
- ... coloor.append(color[i])
- """
- ## Note here enumerate is a python build-In function which return 2 value (counter, value)
- print(coloor) ## print the new list object coloor = ['green','white','black']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement