About 253,000 results
Open links in new tab
  1. Iterating each character in a string using Python

    * unpacks the string into a list and sends it to the print statement. sep='\n' will ensure that the next char is printed on a new line. The output will be: H e l l o W o r l d ! If you do need a loop …

  2. python - Iterate over the lines of a string - Stack Overflow

    The fact that python uses immutable strings means that you must always create a new string, so this has to be done at some point anyway. If your string is very large, the disadvantage is in …

  3. Iterate over a string 2 (or n) characters at a time in Python

    Jul 22, 2009 · Earlier today I needed to iterate over a string 2 characters at a time for parsing a string formatted like "+c-R+D-E" (there are a few extra letters). I ended up with this, which …

  4. Python while loop with string - Stack Overflow

    Jan 27, 2015 · Python while loop condition check for string. 0. Python: Terminating while loop with a string command. 1 ...

  5. Python - How to concatenate to a string in a for loop? [duplicate]

    Nov 23, 2011 · Doing this naively in a loop can be very bad for performance (as in, quadratic slowdown = add one string, need twice the same; it's not a good habit to get into). – …

  6. How do I append one string to another in Python?

    Dec 14, 2010 · $ python -m timeit -s"s=''" "for i in xrange(10):s+='a'" 1000000 loops, best of 3: 1.85 usec per loop $ python -m timeit -s"s=''" "for i in xrange(100):s+='a'" 10000 loops, best of …

  7. Python - Create string with for-loop - Stack Overflow

    Sep 16, 2018 · Python string concatenation loop. 1. for loop to concatenate strings. 0. Concatenate in a "for loop" 0. ...

  8. How do I iterate through a string in Python? - Stack Overflow

    Apr 2, 2015 · import string for c in string.lowercase: print c How get letter frequencies with some efficiency and without counting non-letter characters: import string sample = "Hello there, this …

  9. python - How to iterate string/arrays - Stack Overflow

    Mar 9, 2020 · You could use it like "arrays", but there are many build-in functions that you would find very useful. This is a basic and essential data structure in Python. Most of books or …

  10. Best way to loop over a python string backwards

    Aug 9, 2015 · What is the best way to loop over a python string backwards? The following seems a little awkward for all the need of -1 offset: string = "trick or treat" for i in range(len(string)-1, 0 …

Refresh