Re: Generic dictionary

2016-11-21 Thread Peter Otten
Thorsten Kampe wrote: >> def GenericDict(dict_or_items): >> if isinstance(dict_or_items, dict): >> return dict(dict_or_items) >> else: >> return SimpleGenericDictWithOnlyTheFalseBranchesImplemented( >> dict_or_items >> ) > > That would be a kind of fact

Re: Generic dictionary

2016-11-20 Thread Chris Angelico
On Mon, Nov 21, 2016 at 12:12 AM, Thorsten Kampe wrote: > Chris, it's up to the consumer to decide which key/keyfunc to use. > The lists as keys (that is first element in an tuple) are created on > the fly and not used for anything. They are mutable but not mutated. > > Mutating the list would be

Re: Generic dictionary

2016-11-20 Thread Thorsten Kampe
* Chris Angelico (Sun, 20 Nov 2016 23:35:52 +1100) > I see. So you want to be able to have something that looks and > feels > like a dictionary, but uses a different way of looking things up. > Makes reasonable sense, on the surface. > > Before you go down that route, I strongly recommend reading

Re: Generic dictionary

2016-11-20 Thread Thorsten Kampe
* Steve D'Aprano (Sun, 20 Nov 2016 22:40:19 +1100) > > Further thoughts come to mind, after looking more closely at your code. > > On Sun, 20 Nov 2016 08:27 pm, Thorsten Kampe wrote: > > > def values(inst): > > if isinstance(inst._generic, dict): > > return inst._generic.

Re: Generic dictionary

2016-11-20 Thread Chris Angelico
On Sun, Nov 20, 2016 at 11:19 PM, Thorsten Kampe wrote: > The whole point of my posting was non hashable keys (like lists): > > ``` dictitem > [([1], '11'), ([2], '22'), ([4], '33'), ([3], '44')] dict(dictitem) > - > Typ

Re: Generic dictionary

2016-11-20 Thread Thorsten Kampe
* Steve D'Aprano (Sun, 20 Nov 2016 21:10:08 +1100) > > On Sun, 20 Nov 2016 08:27 pm, Thorsten Kampe wrote: > > > I'd like to extend the dictionary class by creating a class that acts > > like a dictionary if the class is instantiated with a dictionary and > > acts like a "dictitem" ([(key1, value

Re: Generic dictionary

2016-11-20 Thread Thorsten Kampe
* Anny Mous (Sun, 20 Nov 2016 21:46:25 +1100) > > On Sun, 20 Nov 2016 08:43 pm, Peter Otten wrote: > > > Thorsten Kampe wrote: > > > >> [Crossposted to tutor and general mailing list] > >> > >> Hi, > >> > >> I'd like to extend the dictionary class by creating a class that acts > >> like a dict

Re: Generic dictionary

2016-11-20 Thread Thorsten Kampe
* Peter Otten (Sun, 20 Nov 2016 10:43:01 +0100) > > Thorsten Kampe wrote: > > > > I'd like to extend the dictionary class by creating a class that acts > > like a dictionary if the class is instantiated with a dictionary and > > acts like a "dictitem" ([(key1, value1), (key2, value2), ...]) if >

Re: Generic dictionary

2016-11-20 Thread Steve D'Aprano
Further thoughts come to mind, after looking more closely at your code. On Sun, 20 Nov 2016 08:27 pm, Thorsten Kampe wrote: > class GenericDict: > """ > a GenericDict is a dictionary or a list of tuples (when the keys > are not hashable) > """ > def __init__(inst, generic_dict

Re: Generic dictionary

2016-11-20 Thread Anny Mous
On Sun, 20 Nov 2016 08:43 pm, Peter Otten wrote: > Thorsten Kampe wrote: > >> [Crossposted to tutor and general mailing list] >> >> Hi, >> >> I'd like to extend the dictionary class by creating a class that acts >> like a dictionary if the class is instantiated with a dictionary and >> acts lik

Re: Generic dictionary

2016-11-20 Thread Steve D'Aprano
On Sun, 20 Nov 2016 08:27 pm, Thorsten Kampe wrote: > I'd like to extend the dictionary class by creating a class that acts > like a dictionary if the class is instantiated with a dictionary and > acts like a "dictitem" ([(key1, value1), (key2, value2), ...]) if > instantiated with a list (that is

Re: Generic dictionary

2016-11-20 Thread Peter Otten
Thorsten Kampe wrote: > [Crossposted to tutor and general mailing list] > > Hi, > > I'd like to extend the dictionary class by creating a class that acts > like a dictionary if the class is instantiated with a dictionary and > acts like a "dictitem" ([(key1, value1), (key2, value2), ...]) if > i