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

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Tue Feb 24 01:11:29 EST 2009


On Mon, 23 Feb 2009 21:35:21 -0800, collin 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?

This question is ambiguous. It could mean:

int("4") - int("1") 
=> 3

ord("4") - ord("1") 
=> 3

randomlist.index("4") - randomlist.index("1")
=> 3


and possible more as well. Perhaps you should explain what you want to 
do. What do you mean by "distance between strings", and is it important 
that they are in a list?



-- 
Steven



More information about the Python-list mailing list