How to parse a string completely into a list

Tim Roberts timr at probo.com
Thu Sep 25 04:03:02 EDT 2008


john.ford at colorado.edu wrote:
>
>The string draws a map that I then want to be able to traverse
>through. If I can count through the individual characters of a list I
>can create an x-y coordinate plane for navigation.

Well, the point Matt was making is that traversing through a list and
traversing through a string are the same.

  # Given this:
  s = 'abcde'
  l = ['a','b','c','d','e']

  # These are identical:
  for ch in s:
    pass
  for ch in l:
    pass

  # And these are identical:
  print s[3]
  print l[3]

Slicing is identical.  Subsetting is identical.  The only difference is
that I can change an element of the list.
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list