SpecialStack implementation in Python