python - Shift particular range of elements in list -


i want this:

mylist[n]. shift mylist[k:l] left s. 

example: let n 5, s = 1 , k , l 3rd , 4th element in list.

before:

[a,a,b,b,a] 

after:

[a,b,b,a,a] 

to clear: don't want loose 'b' items in list, 'a' can overwritten.

what time , space efficient way achieve in python?

edit: no rotation!

using list slice:

>>> lst = [1, 2, 3, 4, 5] >>> s, k, l = 1, 2, 4 # 4 = 3 + 1 >>> x = lst[k:l] >>> del lst[k:l] >>> lst[k-s:k-s] = x >>> lst [1, 3, 4, 2, 5] 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -