[issue32508] Problem while reading back from a list of lists

J Viswanathan report at bugs.python.org
Sun Jan 7 19:21:39 EST 2018


J Viswanathan <Viswanathan10 at gmail.com> added the comment:

Thanks for your sensible advice to produce
    a short, self-contained and correct example.

        Attached is the input file (35 lines, 770 bytes) and log (14 lines)

    Description of the problem and bug:

    The data consists of 6 triplets.

        The code is to group the data according to the pair in each
        triplet.

    In the data, there are just two pairs [1,3] and [2,2]

        With the pair [1,3] the associated third item in the first
        three triplets are 1, 2, 4.

        (This is printed correctly in the first line of the output).

         The bug is seen on the 4th (non-blank) line:

         klists[0] should be [1,2,4] and not as shown.

         I sincerely hope that I am not wasting your time with a
         non-existent bug.

     J. Viswanathan.

On Sun, Jan 7, 2018 at 8:22 AM, Steven D'Aprano <report at bugs.python.org>
wrote:

>
> Steven D'Aprano <steve+python at pearwood.info> added the comment:
>
> It isn't clear to me what bug you are reporting here:
>
> - What do you mean by "problem reading back from a list of lists"? What
> sort of problem?
>
> - What makes you think that there is a bug in the interpreter, rather than
> in your own code?
>
> We aren't going to debug your code for you: if you have found a bug,
> please report the simplest code that shows the bug. You may find it helpful
> to read this first:
>
> http://sscce.org/
>
> Although it is written for Java, the same applies to Python code too.
>
> I'm closing this ticket for now.
>
> If you simplify your code to something that demonstrates a bug in the
> Python interpreter, rather than a bug in your own code, please re-open this
> ticket with a better description of what the problem is, and the shortest,
> simplest demonstration of that problem that you can come up with.
>
> Thank you.
>
> ----------
> nosy: +steven.daprano
> resolution:  -> not a bug
> stage:  -> resolved
> status: open -> closed
>
> _______________________________________
> Python tracker <report at bugs.python.org>
> <https://bugs.python.org/issue32508>
> _______________________________________
>

----------
Added file: https://bugs.python.org/file47371/hksu_copy.py
Added file: https://bugs.python.org/file47372/hksu.log

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32508>
_______________________________________
-------------- next part --------------


vdata =  [1, 3, 1,
          1, 3, 2,
          1, 3, 4,
          2, 2, 2,
          2, 2, 4,
          2, 2, 7]

uids = []
klists = []
check_uid =[0,0]
klist = []

for x in range(6):
    xslice = vdata[3*x:3*(x+1)]
    lid = xslice[0:2]
    k = xslice[2]

    if (lid == check_uid): #an existing uid
        klist.append(k)
    else:
        check_uid = lid   # a new uid
        uids.append(check_uid) 
        if len(klist):
            klists.append(klist)
            print ('\nx : ', x, 'klist:' , klist)
            klist.clear()
        klist.append(k)

klists.append(klist)   # The last of the klists

print ('\nlen(klists) :', len(klists))

print ('\ni      uids(i)      klists[i] \n')
for i in range(2):
    print ( i, '    ', uids[i], '    ', klists[i])

-------------- next part --------------
-*- mode: compilation; default-directory: "c:/Users/J V/Documents/gamsdir/" -*-
Compilation started at Mon Jan  8 05:32:11

python hksu_copy.py

x :  3 klist: [1, 2, 4]

len(klists) : 2

i      uids(i)      klists[i] 

0      [1, 3]      [2, 4, 7]
1      [2, 2]      [2, 4, 7]

Compilation finished at Mon Jan  8 05:32:12


More information about the Python-bugs-list mailing list