[Tutor] list generation

Mats Wichmann mats at wichmann.us
Mon May 10 17:02:42 EDT 2021


On 5/10/21 12:59 PM, Ed Connell wrote:
> What is the best way to create a list of constant values of a given length?
> 
> gen_list( 78, 4 ) should generate [ 78, 78, 78, 78  ].
> 
> and
> 
> gen_list( 'pop', 2 ) should produce [ 'pop', 'pop' ]
> 
> Thanks,
> 
> Ed
> 

without claiming "best", the * operator works...

x = [78] * 4



More information about the Tutor mailing list