Re: [Tutor] Python Memory Allocation -- deep learning

2018-07-30 Thread Steven D'Aprano
On Tue, Jul 31, 2018 at 02:58:56AM +1000, Steven D'Aprano wrote: > The *only* thing you have seen which is a language feature is this rule: > > - if two objects, a and b, have the same ID *at the same time*, then > "a is b" will be true; > > - if "a is b" is false, then a and b must have diff

Re: [Tutor] Dictionary viceversa

2018-07-30 Thread Alan Gauld via Tutor
On 30/07/18 19:11, Zachary Ware wrote: > On Mon, Jul 30, 2018 at 1:08 PM Alan Gauld via Tutor wrote: >> There are lots of options including those suggested elsewhere. >> Another involves using get() which makes your function >> look like: >> >> def viceversa(d): >> new_d = dict() >> for k

Re: [Tutor] How to add an Image in Grid mode with Python and Tkinter?

2018-07-30 Thread Alan Gauld via Tutor
On 30/07/18 08:24, Matthew Polack wrote: > I'm trying to simply add an image to our program to make the GUI more > interesting...but most of the tutorials describe using the 'Pack' > method not the grid method of layout... That's completely irrelevant since you can add images to widgets regar

Re: [Tutor] How to add an Image in Grid mode with Python and Tkinter?

2018-07-30 Thread Peter Otten
Matthew Polack wrote: > Hi, > > Steadily trying to learn Python and Tkinter here with our students... > > Am working on a simple 'Price of Cereal Crop' calculatorand have made > a start with the code below... > > I'm trying to simply add an image to our program to make the GUI more > intere

Re: [Tutor] Dictionary viceversa

2018-07-30 Thread Zachary Ware
On Mon, Jul 30, 2018 at 1:08 PM Alan Gauld via Tutor wrote: > There are lots of options including those suggested elsewhere. > Another involves using get() which makes your function > look like: > > def viceversa(d): > new_d = dict() > for k in d: > for e in d[k]: > new

Re: [Tutor] Dictionary viceversa

2018-07-30 Thread Alan Gauld via Tutor
On 30/07/18 13:40, Valerio Pachera wrote: > users = {'user1':['office-a', 'office-b'], > 'user2':['office-b'], > 'user3':['office-a','office-c']} > > It's a list of users. > For each user there's a list of room it can access to. > > I wish to get the same info but "sorted" by room. Re

Re: [Tutor] Dictionary viceversa

2018-07-30 Thread Peter Otten
Zachary Ware wrote: > On Mon, Jul 30, 2018 at 12:20 PM Valerio Pachera wrote: >> I was looking to substiture the cicle for e in new_d like this: >> [ new_d[e].append(k) if e in new_d else new_d[e].append(k) for e in >> [ d[k] ] >> but it can't work because 'new_d[e] = []' is missing. > > Hav

Re: [Tutor] Dictionary viceversa

2018-07-30 Thread Zachary Ware
On Mon, Jul 30, 2018 at 12:20 PM Valerio Pachera wrote: > I was looking to substiture the cicle for e in new_d like this: > [ new_d[e].append(k) if e in new_d else new_d[e].append(k) for e in d[k] ] > but it can't work because 'new_d[e] = []' is missing. Have a look at `dict.setdefault` and pla

[Tutor] Dictionary viceversa

2018-07-30 Thread Valerio Pachera
Hi all, consider this dictionary users = {'user1':['office-a', 'office-b'], 'user2':['office-b'], 'user3':['office-a','office-c']} It's a list of users. For each user there's a list of room it can access to. Generalizing, a dictionary with a list for each element. d = {k:list} I wi

Re: [Tutor] Do something on list elements

2018-07-30 Thread Valerio Pachera
- Messaggio originale - > Da: "Tutor Python" > A: "Tutor Python" > Inviato: Sabato, 28 luglio 2018 0:06:55 > Oggetto: Re: [Tutor] Do something on list elements > But better still is a list comprehension: > > l = [s.replace('X','') for s in l) > print(l) Thank you all for the answers. L

Re: [Tutor] Python Memory Allocation -- deep learning

2018-07-30 Thread Steven D'Aprano
On Mon, Jul 30, 2018 at 09:21:01AM -0600, Mats Wichmann wrote: > (id does not necessarily mean memory location, by the way) id() *never* means memory location in Python. id() *always* returns an opaque integer ID number which has no promised meaning except to be unique while the object is alive

Re: [Tutor] Python Memory Allocation -- deep learning

2018-07-30 Thread Max Zettlmeißl via Tutor
On Mon, Jul 30, 2018 at 3:20 PM, Sunil Tech wrote: > Python memory allocation is varying in all these use cases. Please help me > understand. CPython is interning small integers and small strings as a form of optimisation. "The current implementation keeps an array of integer objects for all int

[Tutor] How to add an Image in Grid mode with Python and Tkinter?

2018-07-30 Thread Matthew Polack
Hi, Steadily trying to learn Python and Tkinter here with our students... Am working on a simple 'Price of Cereal Crop' calculatorand have made a start with the code below... I'm trying to simply add an image to our program to make the GUI more interesting...but most of the tutorials describ

Re: [Tutor] Python Memory Allocation -- deep learning

2018-07-30 Thread Steven D'Aprano
On Mon, Jul 30, 2018 at 06:50:59PM +0530, Sunil Tech wrote: > Hi Team, > > I am investigating how the memory allocation happens in Python You cannot investigate memory allocation in Python code, because the Python execution model does not give you direct access to memory. What you can investiga

Re: [Tutor] Python Memory Allocation -- deep learning

2018-07-30 Thread Mats Wichmann
On 07/30/2018 07:20 AM, Sunil Tech wrote: > Hi Team, > > I am investigating how the memory allocation happens in Python There are several things going on here, but the main thing to know is: but Python language _implementations_ optimize when they can and think it makes sense. So don't draw too m

Re: [Tutor] Python Memory Allocation -- deep learning

2018-07-30 Thread Joel Goldstick
On Mon, Jul 30, 2018 at 9:20 AM, Sunil Tech wrote: > Hi Team, > > I am investigating how the memory allocation happens in Python > For Eg: > *Case 1:* > a = 10 b = 10 c = 10 id(a), id(b), id(c) > (140621897573616, 140621897573616, 140621897573616) a += 1 id(a) > 14062

[Tutor] Python Memory Allocation -- deep learning

2018-07-30 Thread Sunil Tech
Hi Team, I am investigating how the memory allocation happens in Python For Eg: *Case 1:* >>> a = 10 >>> b = 10 >>> c = 10 >>> id(a), id(b), id(c) (140621897573616, 140621897573616, 140621897573616) >>> a += 1 >>> id(a) 140621897573592 *Case 2:* >>> x = 500 >>> y = 500 >>> id(x) 4338740848 >>>