You can use operator.itemgetter
:
>>> from operator import itemgetter
>>> bar = ['a','b','c','x','y','z']
>>> itemgetter(0, 3, 4)(bar)
('a', 'x', 'y')
So for your example you would do the following:
>>> v1, v2, v3 = itemgetter(0, 3, 4)(bar)
More Related Contents:
- How does assignment work with list slices?
- Slicing a list in Python without generating a copy
- What is the difference between slice assignment that slices the whole list and direct assignment?
- Pairs from single list
- Can I create a “view” on a Python list?
- How to get last items of a list in Python?
- Extract elements of list at odd positions
- Python Array Slice With Comma?
- Reversing a list using slice notation
- Insert element in Python list after every nth element
- Why python’s list slicing doesn’t produce index out of bound error? [duplicate]
- Slicing list of lists in Python
- Slicing a list into n nearly-equal-length partitions [duplicate]
- Why does reversing a list using slice notation with 0 as “stop” not return the entire list?
- What does += mean in this context?
- How to name a file using a value in a list in a dictionary?
- Why does append() always return None in Python? [duplicate]
- Convert all strings in a list to int
- Get unique values from a list in python [duplicate]
- List comprehension vs generator expression’s weird timeit results?
- How do I loop through a list by twos? [duplicate]
- converting a list of integers into range in python
- How can I find same values in a list and group together a new list?
- Numpy: views vs copy by slicing
- How to flatten a tuple in python
- Why does df.apply(tuple) work but not df.apply(list)?
- How to concatenate element-wise two lists in Python [duplicate]
- Identify duplicate values in a list in Python
- Turning a list into nested lists in python
- Creating a dictionary with list of lists in Python