[issue39338] Data lost randomly from dictionary after creating the dictionary

2020-01-14 Thread Tim Peters


Tim Peters  added the comment:

No problem!  If you are trying to swap the values in two variables `x` and `y`, 
in most languages that's spelled:

temp = x
x = y
y = temp

and that works in Python too.  But in Python it's more common to do it with a 
one-liner:

x, y = y, x

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39338] Data lost randomly from dictionary after creating the dictionary

2020-01-14 Thread Y3Kv Bv


Y3Kv Bv  added the comment:

I'm a newbie at Python, also obviously not thinking hard enough over Python's 
mechanics. Shame on me.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39338] Data lost randomly from dictionary after creating the dictionary

2020-01-14 Thread Tim Peters


Change by Tim Peters :


--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39338] Data lost randomly from dictionary after creating the dictionary

2020-01-14 Thread Tim Peters


Tim Peters  added the comment:

What, exactly, in the output shows "the problem"?  When I run it, the `a == b` 
part is always True, while `len(x)` and `len(crazyQuilt2)` are always 30.  The 
other three (len(coordinates), len(x2), len(x3)) are always equal to each 
other, but are monotonically non-increasing across output lines.  For example, 
a typical block of output lines:

(True, 30, 30, 30, 30, 30)
(True, 30, 30, 30, 30, 30)
(True, 30, 30, 30, 30, 30)
(True, 30, 30, 30, 30, 30)
(True, 19, 30, 30, 19, 19)
(True, 19, 30, 30, 19, 19)
(True, 19, 30, 30, 19, 19)
(True, 12, 30, 30, 12, 12)
(True, 12, 30, 30, 12, 12)
(True, 12, 30, 30, 12, 12)

None of that surprises me.  Exactly what about it surprises you?  Or do you get 
different kinds of output (and, if so, exactly what?)?

Here's my guess:  you _intended_ these two lines:

  crazyQuilt2[coordinate2Index] = crazyQuilt2[index]
  crazyQuilt2[index] = crazyQuilt2[coordinate2Index]

to _swap_ the values at indices `index` and `coordinate2Index`.  But they 
don't.  They copy the value originally at `index` into the `coordinate2Index` 
position, and leave the value originally at `index` untouched.

As more copies randomly build up, anything that builds a set or dict out of the 
list naturally gets smaller.

--
nosy: +tim.peters -zach.ware
resolution: not a bug -> 
stage: resolved -> 
status: closed -> open

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39338] Data lost randomly from dictionary after creating the dictionary

2020-01-14 Thread Zachary Ware


Zachary Ware  added the comment:

I suspect your `useAmp` branch is not doing what you think it's doing: it's 
effectively replacing a random number of entries in your `crazyQuilt2` list 
with a duplicate entry (try `print`ing the list every time around the main loop 
to see what's happening to it).  When you later create a dict using the entries 
of the list as keys there are only so many unique keys, and thus the dict is 
not the same length as the list.

--
nosy: +zach.ware
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39338] Data lost randomly from dictionary after creating the dictionary

2020-01-14 Thread Y3Kv Bv


New submission from Y3Kv Bv :

Windows 7 x64, Python 3.8.1

I've encountered a very weird issue where after creating a dictionary from a 
list the dictionary ends up being shorter/data is lost from it.
It's absolutely random when it loses, how many and which items are lost.

I've attached the example file with the code that always has a chance to 
trigger the issue for me.

I've managed to figure only this much that when "if useAmp" never triggers, 
data loss will never occur. I've added checkpoints to verify where the loss 
occurs and it's not caused by "if useAmp" block directly, data loss happens 
exactly after the dictionary is created.

--
files: test.py
messages: 360007
nosy: Y3Kv Bv
priority: normal
severity: normal
status: open
title: Data lost randomly from dictionary after creating the dictionary
type: behavior
versions: Python 3.8
Added file: https://bugs.python.org/file48841/test.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com