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

Rotating items of list to left #66322

Closed
SaiKrishnaG mannequin opened this issue Aug 2, 2014 · 2 comments
Closed

Rotating items of list to left #66322

SaiKrishnaG mannequin opened this issue Aug 2, 2014 · 2 comments
Labels
OS-windows type-bug An unexpected behavior, bug, or error

Comments

@SaiKrishnaG
Copy link
Mannequin

SaiKrishnaG mannequin commented Aug 2, 2014

BPO 22124
Nosy @zware
Files
  • rotate_left3.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 2014-08-02.21:34:29.858>
    created_at = <Date 2014-08-02.20:35:33.904>
    labels = ['type-bug', 'invalid', 'OS-windows']
    title = 'Rotating items of list to left'
    updated_at = <Date 2014-08-02.21:34:29.856>
    user = 'https://bugs.python.org/SaiKrishnaG'

    bugs.python.org fields:

    activity = <Date 2014-08-02.21:34:29.856>
    actor = 'zach.ware'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-08-02.21:34:29.858>
    closer = 'zach.ware'
    components = ['Windows']
    creation = <Date 2014-08-02.20:35:33.904>
    creator = 'Sai.Krishna.G'
    dependencies = []
    files = ['36215']
    hgrepos = []
    issue_num = 22124
    keywords = []
    message_count = 2.0
    messages = ['224586', '224590']
    nosy_count = 2.0
    nosy_names = ['zach.ware', 'Sai.Krishna.G']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue22124'
    versions = ['Python 2.7']

    @SaiKrishnaG
    Copy link
    Mannequin Author

    SaiKrishnaG mannequin commented Aug 2, 2014

    Hi, I am trying to rotate list of 3 to left
    for this I am trying to define this function
    def rotate_left3(nums)

    #argument nums is list
    for example
    rotate_left3([1, 2, 3])
    I am expecting value [2,3,1] in return. I have written the following code
    a = nums
    a[0]=nums[1]
    a[1]=nums[2]
    a[2]=nums[0]
    return a #this is returning [2,3,2] instead of [2,3,1]
    however if I assign
    a = [0,0,0] #or any other value other than directly assigning nums
    the code works perfectly

    @SaiKrishnaG SaiKrishnaG mannequin added OS-windows type-bug An unexpected behavior, bug, or error labels Aug 2, 2014
    @zware
    Copy link
    Member

    zware commented Aug 2, 2014

    This is not a bug. The assignment "a = nums" doesn't create a copy of "nums", it just assigns the name "a" to the same object that "nums" refers to. Since lists are mutable, changes made to "a" are visible through the name "nums". By the time you do "a[2] = nums[0]", "nums[0]" has been reassigned.

    Have a look at this article: http://nedbatchelder.com/text/names.html

    Also, you may want to look at collections.deque and its rotate method.

    @zware zware closed this as completed Aug 2, 2014
    @zware zware added the invalid label Aug 2, 2014
    @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
    OS-windows type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant