SyntaxFix
Write A Post
Hire A Developer
Questions
If you already know the indices:
list1 = ['x','y','z','a','b','c','d','e','f','g'] indices = [(0, 4), (5, 9)] print [list1[s:e+1] for s,e in indices]
Note that we're adding +1 to the end to make the range inclusive...