[Solved] Data Manipulation in accordance with a Pattern in Python [closed]


Try the following code:

def series(x, pattern):
    pattern = [pattern[i:i+2] for i in range(0, len(pattern), 2)]
    start = x
    results = []
    for k in pattern:
        for i in range(5):
            start = eval('start+%s' %(k))
            results.append(start)
    return results

This runs as:

>>> series(70, "+1+3-2-1")
[71, 72, 73, 74, 75, 78, 81, 84, 87, 90, 88, 86, 84, 82, 80, 79, 78, 77, 76, 75]

The above code just uses 4 basic for loops to add/subtract the specific values the specified amount of times.

3

solved Data Manipulation in accordance with a Pattern in Python [closed]