How to make for loop faster in python?

Let’s learn how to make for loop faster in python. The most accurate or helpful solution is served by Stack Overflow.

There are ten answers to this question.

Best solution

how do you make a For loop when you don't need index in python?

if i need a for loop in python for i in range(1,42): print "spam" but don't use the "i" for anything pylint complains about the unused variable. How should i handle this? I know you can do this: for dummy_index in range(1,42): print "spam" but doing this seems quite strange to me, is there a better way? I'm quite new at python so forgive me if I'm missing something obvious.

Answer:

There is no "natural" way to loop n times without a counter variable in Python, and you should...

Read more

Jacxel at Stack Overflow Mark as irrelevant Undo

Other solutions

How would I make a studying program in python?

I am trying to make a program that will display a word at random word. Then I am prompted to give a translation. If I'm right or wrong it will say so and then display the next word for me to translate. I am completely new to python, so I'm not sure exactly...

Answer:

Python has a powerful List feature which would suit your needs. You could either create two lists and...

Read more

Aoi at Yahoo! Answers Mark as irrelevant Undo

How do I stop a while-loop?

I have tried to make a console-based calculator, and everything works, except I cannot set the while-loop to False. :/ I started learning Python again today, (not that I had that much experience earlier), and started using Codecademy today, again. from...

Answer:

just use break

Read more

Montassar ben Hadj Abdallah at Quora Mark as irrelevant Undo

Answer:

Well, you could try casting the captured string to a float, to see whether you get a number or not....

Read more

Matthew at Yahoo! Answers Mark as irrelevant Undo

What are the quickest Python alternatives to Perl one-liners like "perl -n -e ..."?

It seems no obvious brief command-line alternatives exist except the more verbose "python -c ..." (which requires writing imports, a loop, etc.). Are there other alternatives or tools to make this quicker? Cf. http://stackoverflow.com/questio...

Answer:

Python does not lend itself well to dense one-liners. I would argue this is a plus. :-) If you need...

Read more

Vaibhav Mallya at Quora Mark as irrelevant Undo

Determine the minimum compression d of the spring that enables the block to just make it through the loop-the-?

A massless spring of constant k = 85.2 N/m is fixed on the left side of a level track. A block of mass m = 0.50 kg is pressed against the spring and compresses it a distance of d. The block (initially at rest) is then released and travels toward a circular...

Answer:

You will have to account for all the energy involved in this setup. Your mistake here is that you haven...

Read more

jpfeff at Yahoo! Answers Mark as irrelevant Undo

How difficult is it to make Python web applications scale?

I would be interested to learn about any type of challenge people face when scaling python websites, except those that are common to every large scale web application (databases). In particular I am thinking about ultra large scale. (Is YouTube still...

Answer:

I expect you would see a much greater scalability boost from an async python framework (like tornado...

Read more

Jason Kane at Quora Mark as irrelevant Undo

Answer:

Depends on what libraries and external interfaces are in use in the Python 2 code.   If the Python ...

Read more

R. Drew Davis at Quora Mark as irrelevant Undo

Could someone help me on the For loop in this program(I have broke this up to make it easy to read)?

This is the program I am createing , I have the broke up part below and below the sections I name is my actual partually completly code 2/3 is done and I am now stuck on doing the for loop. Could someone please explain how one works and what lines of...

Answer:

You forgot to tell what is your problem, when you say "broken" what it means ?? (not working...

Read more

Brian M at Yahoo! Answers Mark as irrelevant Undo

Is there a non-while loop Python equivalent of Java / C standard for loop with counter?

In particular, I'd like to replicate the following functionality in Python, without using a while loop. for (int i = 0; i < 10; i++){ if (i == 5) i++; } A more realistic example, to set the context: for (int i = 0; i < myarray.length; i++)...

Answer:

In response to your "realistic example", you can loop over a generator [1]. >>...

Read more

Noah Seger at Quora Mark as irrelevant Undo

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.