Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - creating patterned lists

In my current Python project, I need to create some long lists of integers for later use in plots. Currently I'm attacking this in the following way:

volume_axis = []

for values in stripped_header: 
    for doses in range(100):  
        volume_axis.append(int(values))

This code will append to my blank list, giving me the first value in stripped header 100 times, then the next value in stripped header 100 times etc.

Is there a more elegant and pythonesque way to accomplish this?

like image 853
user1764386 Avatar asked Dec 11 '25 14:12

user1764386


1 Answers

for values in stripped_header: 
    volume_axis += [int(values)] * 100

or using itertools (may be more efficient)

from itertools import repeat
for values in stripped_header:
    volume_axis += repeat(int(values), 100)
like image 160
John La Rooy Avatar answered Dec 13 '25 03:12

John La Rooy