Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

making assignments to an empty two dimensional list #58133

Closed
drathlian mannequin opened this issue Feb 2, 2012 · 2 comments
Closed

making assignments to an empty two dimensional list #58133

drathlian mannequin opened this issue Feb 2, 2012 · 2 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@drathlian
Copy link
Mannequin

drathlian mannequin commented Feb 2, 2012

BPO 13925
Nosy @mdickinson
Files
  • twoDimensionalList.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2012-02-02.00:47:08.345>
    created_at = <Date 2012-02-02.00:40:48.436>
    labels = ['type-bug', 'invalid']
    title = 'making assignments to an empty two dimensional list'
    updated_at = <Date 2012-02-02.00:47:08.343>
    user = 'https://bugs.python.org/drathlian'

    bugs.python.org fields:

    activity = <Date 2012-02-02.00:47:08.343>
    actor = 'mark.dickinson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-02-02.00:47:08.345>
    closer = 'mark.dickinson'
    components = []
    creation = <Date 2012-02-02.00:40:48.436>
    creator = 'drathlian'
    dependencies = []
    files = ['24390']
    hgrepos = []
    issue_num = 13925
    keywords = []
    message_count = 2.0
    messages = ['152450', '152451']
    nosy_count = 2.0
    nosy_names = ['mark.dickinson', 'drathlian']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue13925'
    versions = ['Python 2.7']

    @drathlian
    Copy link
    Mannequin Author

    drathlian mannequin commented Feb 2, 2012

    I might be missing something, but I am expecting the following code to print out a list of lists with each internal list holding one number[0-4], but instead the internal lists are a copy of the list "count".

    #!/usr/bin/python
    count = range(4)
    twoDimensionList = [[]] * len(count)
    for i in range(len(count)):
       twoDimensionList[i].append(count[i])
    print twoDimensionList

    Should print:
    [[0], [1], [2], [3]]

    but erroneously prints:
    [[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]]

    @drathlian drathlian mannequin added the type-bug An unexpected behavior, bug, or error label Feb 2, 2012
    @mdickinson
    Copy link
    Member

    This isn't a bug, but a known gotcha: see.

    http://docs.python.org/faq/programming.html#how-do-i-create-a-multidimensional-list

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant