How do I count the distance between strings in a list?

Jonathan Gardner jgardner at jonathangardner.net
Tue Feb 24 01:08:28 EST 2009


On Feb 23, 9:35 pm, collin <chaosm... at gmail.com> wrote:
> For example, if I were to have the code
>
> randomlist = ["1", "2", "3", "4"]
>
> And I want to count the distance between strings "1" and "4" which is
> 3, what command can I use to do this?

You'd have to get the indexes of the two items and subtract them.
There is an 'index' method on the List object for that.



More information about the Python-list mailing list