Alex Rivera | Logout

Why do python lists have pop() but not push()

Asked 2009-10-14T13:34:26.600
320

Does anyone know why Python's list.append method is not called list.push, given that there's already a list.pop that removes and returns the last element (indexed at -1) and list.append semantic is consistent with that usage?

Edit
Report

2 Answers

11

Because it appends an element to a list? Push is usually used when referring to stacks.

answered 2009-10-14T13:37:03.940
3

Ok, personal opinion here, but Append and Prepend imply precise positions in a set.

Push and Pop are really concepts that can be applied to either end of a set... Just as long as you're consistent... For some reason, to me, Push() seems like it should apply to the front of a set...

answered 2009-10-14T13:42:32.183

Your Answer