classification
Title: Dictionary comprehension using older division behavior
Type: Stage: resolved
Components: Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Amol Sharma, eric.smith
Priority: normal Keywords:

Created on 2020-05-24 21:36 by Amol Sharma, last changed 2020-05-24 22:08 by Amol Sharma. This issue is now closed.

Messages (3)
msg369833 - (view) Author: Amol Sharma (Amol Sharma) Date: 2020-05-24 21:36
Using comprehension to divide all the values in a dictionary like in the following results in integer division in 3.8.

some_dict = {k: v/5 for k, v in some_dict.items()}

This was solved by changing 5 to 5.0, reflecting behavior from python2. I would have expected to have the use the // operator for integer division.

Please correct me if this is expected behavior!
msg369835 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-05-24 22:05
That's not what I see:

$ python3.8
Python 3.8.0b4 (default, Sep 15 2019, 15:56:44)
[GCC 7.4.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> some_dict = {3:4}
>>> {k: v/5 for k, v in some_dict.items()}
{3: 0.8}
>>>

Granted, this is a beta of 3.8 on cygwin, so maybe it's an outlier.

Can you show us a similar interactive session so we can see exactly what platform you're on, and what results you're seeing?
msg369836 - (view) Author: Amol Sharma (Amol Sharma) Date: 2020-05-24 22:08
My apologies! I didn't realize I was in a different environment which was actually 2.7.
History
Date User Action Args
2020-05-24 22:08:37Amol Sharmasetstatus: open -> closed
resolution: not a bug
messages: + msg369836

stage: resolved
2020-05-24 22:05:29eric.smithsetnosy: + eric.smith
messages: + msg369835
2020-05-24 21:36:37Amol Sharmacreate