How can I do the following in a more concise, “pythonic” way:
for element in some_list:
if some_condition:
element.some_attr = some_value
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.
The only thing that’s not pythonic in your code is that you’re not using 4 spaces for indentation.
“Pythonic” doesn’t always mean “concise”; for example the following is shorter, but less readable than your loop:
So, stick to the code you have.