On 2020-08-25 13:52, Daniel. wrote:
I just came across this again while implementing an parser

I would like to compare stack elements as

if stack[-3] == x and stack[-2] == y and stack[-1] == z

if stack[-3 : ] == [x, y, z]:

and somewere below

elif stack[-1] == t

elif stack[-1 : ] == [t]:

I had to spread `len(stack)` in a lot of places.

You can use slicing to reduce the number of `len(stack)`.

People said about the length of a list is usually known, but when you use it as a stack is the oposit.

[snip]
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/ANGXRSPIQIZL67U2H4G4AEZRA4WF4PAB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to