Python-Order a list so that X follows Y and Y follows X
django, python
Solution
You can use `itertools.chain.from_iterable` and `zip`:
>>> data = [1,2,3,4]
>>> tweets = ['a','b','c','d']
>>> list(chain.from_iterable(zip(data,tweets)))
[1, 'a', 2, 'b', 3, 'c', 4, 'd']
Use `itertools.izip` for memory efficient solution.
Problem
So I am using the python chain method to combine two querysets (lists) in django like this. ``` results=list(chain(data,tweets[:5])) ``` Where data and tweets are two separate lists. I now have a "results" list with both data and tweet objects that I want ordered in this fashion. ``` results=[data,tweets,data,tweets,data,tweets] ``` What is the best way to achieve this kind of ordering? I tried using random.shuffle but this isnt what I want.