task: {x*y such that x belongs to S & y is iteration count }
where S is some other set
something like this:
j=0
[i*j for j++ and i in S]
[s1*1, s2*2, s3*3...]
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.
for your edited question, you want
python doesn’t have
++because it keeps a clear distinction between statements and expressions. useanother way to do this is
and yet another way is
I think that the first is the best way to do it because it reduces function calls and is the most readable.
Also, if you don’t know that you absolutely need a list, use a generator expression
This will allow you to process the results one at a time and never store a whole list in memory. You can pass a generator expression to stuff like
sum,max,minand most other builtins.