[Chicago] List revolution

Massimo Di Pierro mdipierro at cs.depaul.edu
Sat Sep 10 18:29:07 CEST 2011

```I have a proposal to resolve the issue

class List(list):
"""
>>> a=List()
>>> for i in range(100000): a.append(i)
>>> print a.first
0
>>> print a.second
1
>>> print a.third
2
>>> print a.twentieth
19
>>> print a.twentysecond
21
>>> print a.onehundredthirtyfifth
134
>>> print a.onethousandfivehundredandthirtyeighth
1537
"""
def __getattr__(self,name):
import re
if name.endswith('first'): name = name[:-5]+'one'
elif name.endswith('second'): name = name[:-6]+'two'
elif name.endswith('third'): name = name[:-5]+'three'
elif name.endswith('fth'): name = name[:-3]+'ve'
elif name.endswith('hth'): name = name[:-3]+'th'
elif name.endswith('ieth'): name = name[:-4]+'y'
elif name.endswith('th'): name = name[:-2]
subs = {
'one':'+1',
'two':'+2',
'three':'+3',
'four':'+4',
'five':'+5',
'six':'+6',
'seven':'+7',
'eigth':'+8',
'nine':'+9',
'ten':'+10',
'eleven':'+11',
'twelve':'+12',
'thirteen':'+13',
'fourteen':'+14',
'fiftheen':'+15',
'sixteen':'+16',
'seventeen':'+17',
'eighteen':'+18',
'nineteen':'+19',
'ten':'+10',
'twenty':'+20',
'thirty':'+30',
'fourty':'+40',
'fifthy':'+50',
'sixtith':'+60',
'seventy':'+70',
'eighty':'+80',
'ninety':'+90',
'hundred':')*100+(',
'thousand':')*1000+(',
'million':')*1000000+(',
'billion':')*1000000000+(',
'trillion':')*100000000000+(',
'and',''}
for key,value in subs.items(): name = name.replace(key,value)
if '(' in name: name='('+name+')'
name.replace('()','1')
if not re.compile('[\d\+\*\(\)]+').match(name): return AttributeError
try: return self[eval(name)-1]
except: raise AttributeError

On Sep 10, 2011, at 10:15 AM, Sal Lara wrote:

> I think it's super-overdue. I honestly can't even think of that many places in my code where I depend on the actual numerical index value of a list element. That in and of itself isn't very pythonic, right? However, were the first list element actually 1, many who answer yes to my question might feel differently.
>
> -Sal
>
> On Sat, Sep 10, 2011 at 10:03 AM, Tathagata Dasgupta <tathagatadg at gmail.com> wrote:
> What do guys think of list revolution?
>
> http://mail.python.org/pipermail/python-ideas/2011-September/011448.html
>
>
> --
> Cheers,
> T
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20110910/2f171626/attachment.html>
```