Re: like a "for loop" for a string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alexnb

    #1

    Re: like a "for loop" for a string


    Basically I want the code to be able to pick out how many strings there are
    and then do something with each, or the number. When I say string I mean how
    many "strings" are in the string "string string string non-string string"

    Does that help?


    Fredrik Lundh wrote:
    >
    Alexnb wrote:
    >
    >Ya just an example, to print the numbers 1-5
    >
    Sorry, I still don't have the slightest idea what you expect the code to
    do.
    >
    </F>
    >
    >>>But I am wondering is there a way to something like this:
    >>>>
    >>>funString = "string string string non-string non-string string"
    >>>and
    >>>for "string" in funString:
    >>> print something
    >>>>
    >>>I know you can't do that; but, is there a way do do something similar
    >>>that
    >>>gets the same result?
    >>
    >>you seem to have forgotten to specify the result. or did you mean that
    >>the above should print 1-5?
    >
    --

    >
    >
    --
    View this message in context: http://www.nabble.com/like-a-%22for-...p19022694.html
    Sent from the Python - python-list mailing list archive at Nabble.com.

  • Grzegorz Staniak

    #2
    Re: like a &quot;for loop&quot; for a string

    On 2008-08-17, Alexnb <alexnbryan@gma il.comwroted:
    Basically I want the code to be able to pick out how many strings
    What do you mean by "string"?

    foo = "abc abc cde abc ijk abc cde abc"

    "foo" is one "string". If you want substrings, specify what kind of substrings
    you mean. All occurences of "abc", for example.
    there are
    and then do something with each, or the number. When I say string I mean how
    many "strings" are in the string "string string string non-string string"
    Do you mean something like "count and return all occurences of the substring
    'abc' in foo"? Looks like you should use the re module.

    GS
    --
    Grzegorz Staniak <gstaniak _at_ wp [dot] pl>

    Comment

    Working...