python list modification to list of lists
Question: I am trying to learn python (just finished _Learn Python the Hard Way_ book!),
but I seem to be struggling a bit with lists. Specifically speaking, I have a
list like so:

    
    
    x = ["/2.ext", "/4.ext", "/5.ext", "/1.ext"]
    

I would like to operate on this above list, so that it returns a list
(somehow!) like so:

    
    
    y = [ ["/1.ext", "/2.ext"], ["/1.ext", "/2.ext", "/3.ext, "/4.ext"], ["/1.ext", "/2.ext", "/3.ext", "/4.ext", "/5.ext"], ["/1.ext"] ]
    

So, essentially, each element in `x` is now turned to a list of lists. I could
probably loop over `x`, store all the sequence lists in another list and then
merge then together - but it just seems like there must be a better way to do
it.

Would be grateful if someone could point me in the right direction to solve
this problem.

EDIT (taking into account Martijn's comments):

Specifically, I want to generate the intermediary filenames in a sequence,
ending at the number for each x list element


Answer: You can do it as follows:

    
    
    x = ["/2.ext", "/4.ext", "/5.ext", "/1.ext"]
    
    print [['/{}.ext'.format(j) for j in range(1,int(i[1])+1)] for i in x]
    
    [OUTPUT]
    [['/1.ext', '/2.ext'], ['/1.ext', '/2.ext', '/3.ext', '/4.ext'], ['/1.ext', '/2.ext', '/3.ext', '/4.ext', '/5.ext'], ['/1.ext']]
    

This only works for digits upto 9. I'll post update for more general solutions

HERE is the more general solution. Works for any numbers:

    
    
    import re
    
    x = ["/2.ext", "/4.ext", "/5.ext", "/1.ext"]
    
    print [['/{}.ext'.format(j) for j in range(1,int(re.search(r'\d+',i).group(0))+1)] for i in x]
    

