Skip to content

Issue with List of Lists #105671

Closed as not planned
Closed as not planned
@arungansi

Description

@arungansi

Hello,

I create a list of lists as below:

  n_classes = 12
  label_lists = [[]] * n_classes

then i tried append a value for one the list item within the mail list

for i in range(n_classes):
    label_lists[i].extend('a')
label_lists

The output is

  [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
   [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
   [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
   [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
   [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
   [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
   [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
   [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
   [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
   [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
   [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
   [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]

it should have been

[[0],[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions