I’d like to get a list where each item is set to a certain value (in my case, 0). I’ve solved this in my code with the code below, but it feels so messy. Surely there’s a better way?
maxWidths = map(lambda x: 0, range(0, maxCols))
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Multiply a one-element list by the desired length.
In the above, all elements of the list will be the same objects.
In case you’re be creating a list of mutable values (such as dicts or lists), and you need them to be distinct, you can either use
mapas you did in the question, or write an equivalent list comprehension: