This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients mark.dickinson, rhettinger, serhiy.storchaka, tim.peters
Date 2016-01-26.06:38:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1453790303.44.0.872538997694.issue26194@psf.upfronthosting.co.za>
In-reply-to
Content
Another take: Do a regular insertion with no special cases, followed by a pop from the right:

>>> for i in range(len(d) + 1):
	s = list(d)
	s.insert(i, None)      
	_ = s.pop()
	print(i, s)
	
0 [None, 'a', 'b']
1 ['a', None, 'b']
2 ['a', 'b', None]
3 ['a', 'b', 'c']

Nice parts:
* Doesn't change pop direction depending on the inputs
* Guarantee that entries to the left of i will keep their position.
* Post condition of d[i]==newelem applies whenever i exists.

Not nice part:
* Initially surprising that d.insert(len(d), newelem) does not actually insert newelem.
* d.insert(len(d), newelem) not the same as d.append(newelem).

Another alternative is to raise an exception for the one case where index==maxlen, with the theory being that d[index] won't be a valid index so you can't insert anything there.
History
Date User Action Args
2016-01-26 06:38:23rhettingersetrecipients: + rhettinger, tim.peters, mark.dickinson, serhiy.storchaka
2016-01-26 06:38:23rhettingersetmessageid: <1453790303.44.0.872538997694.issue26194@psf.upfronthosting.co.za>
2016-01-26 06:38:23rhettingerlinkissue26194 messages
2016-01-26 06:38:23rhettingercreate