Re: Advantages of Default Factory in Dataclasses

2021-11-16 Thread Alan Bawden
David Lowry-Duda writes: ... For the same reason that the following code doesn't do what some people might expect it to: ```python def add_to(elem, inlist=[]): inlist.append(elem) return inlist list1 = add_to(1) list2 = add_to(2) print(list1) # prints [1

Re: Alternatives to Jupyter Notebook

2021-11-16 Thread Martin Schöön
Den 2021-11-15 skrev Loris Bennett : > Martin Schöön writes: > >> Den 2021-10-20 skrev Shaozhong SHI : >>> >>> My Jupyter notebook becomes unresponsive in browsers. >>> >> Odd, I never had any problems like that. I use Firefox on Linux. >> >>> Are there alternatives to read, edit and run Jupyter N

Re: One line sort

2021-11-16 Thread Christian Gollwitzer
Am 15.11.21 um 14:10 schrieb ast: A curiosity: q = lambda x: x and q([i for i in x[1:] if i < x[0]]) + [x[0]] + q([i for i in x[1:] if i >= x[0]]) >>> q([7, 5, 9, 0]) [0, 5, 7, 9] That seems to be a translation of the classic Haskell quicksort example: qsort [] = [] qsort (x:xs) = qsort [

Re: Advantages of Default Factory in Dataclasses

2021-11-16 Thread David Lowry-Duda
On Tue, Nov 16, 2021 at 05:04:05PM +0400, Abdur-Rahmaan Janhangeer wrote: > A simple question: why do we need field(default_factory ) in > dataclasses? For the same reason that the following code doesn't do what some people might expect it to: ```python def add_to(elem, inlist=[]): inlist.a

Re: Advantages of Default Factory in Dataclasses

2021-11-16 Thread dn via Python-list
On 17/11/2021 02.04, Abdur-Rahmaan Janhangeer wrote: > A simple question: why do we need field(default_factory ) in dataclasses? > > Why not make that field as an attribute return a function? > > Useful implementation examples / use cases appreciated. It's an interesting question: We could defi

Re: Advantages of Default Factory in Dataclasses

2021-11-16 Thread Paul Bryan
On Tue, 2021-11-16 at 17:04 +0400, Abdur-Rahmaan Janhangeer wrote: > A simple question: why do we need field(default_factory ) in > dataclasses? To initialize a default value when a new instance of the dataclass is created. For example, if you want a field to default to a dict. A new dict is crea

Advantages of Default Factory in Dataclasses

2021-11-16 Thread Abdur-Rahmaan Janhangeer
Greetings list, A simple question: why do we need field(default_factory ) in dataclasses? Why not make that field as an attribute return a function? Useful implementation examples / use cases appreciated. Kind Regards, Abdur-Rahmaan Janhangeer about | blog