I’m looking for a loop construct like for i in list where i < n. I would like to replace this mess:
for i in list:
if i < n:
#logic here
Is there something more compact and more elegant?
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.
I’d write it with a guard condition to avoid the layer of indentation.
A one-liner is this:
But I think the obvious code with the if inside the loop is much easier to understand.