Create a list by picking an odd-index items from the first list and even index items from the second using python programming
belongs to collection: Python Data Structure Exercises
All Answers
total answers (1)
belongs to collection: Python Data Structure Exercises
total answers (1)
Hint:
Use list slicing
Solution:
To access a range of items in a list, use the slicing operator
:. With this operator, you can specify where to start the slicing, end, and specify the step.For example, the expression
list1[ start : stop : step]returns the portion of the list from index start to index stop, at a step size step.- for 1st list: Start from the 1st index with step value 2 so it will pick elements present at index 1, 3, 5, and so on
- for 2nd list: Start from the 0th index with step value 2 so it will pick elements present at index 0, 2, 4, and so on
need an explanation for this answer? contact us directly to get an explanation for this answer