Re: list access

jon klein <[email protected]>
Newsgroups gmane.comp.breve
Message-ID <[email protected]>
On Sunday, August 31, 2003, at 04:49  PM, Rick Giuly wrote:

> I'm looking for a way to:
> -determine the length of a list

The length of the list should be given simply by using the list in
the context of an int.

If you have a situation in which the context does not force it to be
an int (such as a "print" statement, which can accept both lists and
ints), you can force it yourself:

print (myList + 0).	# forces the list to become an int

> -get the last element of a list without popping it (if possible)

Once you have the length of the list, you can use that to get the
last element.  For example:

length = (myList + 0).
print myList{ length - 1 }.

- jon

_______________________________________________
breve mailing list
[email protected]
http://www.spiderland.org/mailman/listinfo/breve
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.