« Back to Index

[Python algorithm to generate single list]

View original Gist on GitHub

Tags: #algorithm #python

Python algorithm to generate single list.py

"""
We need a single list.

The starting list is `n`.

We need to intersperse each item in `l` at positions 2 and 4.

We need to intersperse each item in `u` at positions 3.

But the list needs to be considered in chunks of six.

Meaning, the following example is wrong (as the positions 2, 3 and 4 aren't applied with chunks of 6 items in mind)...

[1, a, A,
 b, 2, c,
 B, d, 3,
 e, C, f]
 
> The above is wrong because the interspersing is reset after position 4 (so counting positions 1, 2, 3 ...etc has started again after the position where `b` is found).
 
But the following is the correct output...

[1, a, A,
 b, 2, 3,
 4, c, B,
 d, 5, 6]
"""

import itertools
import string

n = list(range(1, 27))
l = list(string.ascii_lowercase)
u = list(string.ascii_uppercase)

...