[Python-ideas] __call__ on lists, dicts etc.

2020-10-05 Thread george . winton . harding
Hi all, I've been working in q and k, which is where this idea comes from. My idea is to make lists and dicts callable, with __call__ = __getitem__. So that: [3,4,5](1) gives 4 {'a':1, 'b': 2}('b') gives 2 Arguably a list is a function which maps from range(len(list)) to the list entries, and

[Python-ideas] Re: __call__ on lists, dicts etc.

2020-10-05 Thread Ricky Teachey
Well there is already a function you can call for these, __getitem__: lst_getter = lst.__getitem__ map( lst_getter, idxs) sorted(range(len(lst)), key=lst_getter) max(range(len(lst)), key=lst_getter) dct_getter = dct.__getitem__ map(dct, lst) instead of (dct[l] for l in lst) If you find yourself

[Python-ideas] Re: __call__ on lists, dicts etc.

2020-10-05 Thread Christopher Barker
Please no. If you want lisp, use lisp (or something in the lisp family) On Mon, Oct 5, 2020 at 5:53 AM Ricky Teachey wrote: > If you find yourself preferring this map() style of code a lot (rather than using generator expressions), you can make a utility function: def getter(obj): return obj

[Python-ideas] Method to efficiently advance iterators for sequences that support random access

2020-10-05 Thread Kevin Mills
str_iterator, bytes_iterator, range_iterator, list_iterator, and tuple_iterator (and probably others) should have a method that is capable of efficiently advancing the iterator, instead of having to call next repeatedly. I suggest adding an itertools.advance function which dispatches to a dunder

[Python-ideas] Re: Method to efficiently advance iterators for sequences that support random access

2020-10-05 Thread Marco Sulla
You can use slice: new_iterator = iterator[50001:] it2 = iter(new_iterator) or range: for i in range(50001, len(iterator)): x = iterator[i] ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@