use:
tmp_list = list[:]
this will create a copy instead of a reference.
Also `list` is a python object type name, use 'list_' as variable name
instead of `list`

On Sun, Nov 5, 2017 at 7:37 PM, Virbhadra Gupta <[email protected]>
wrote:

>
>
> i was trying to sort list by only 0 and other Numbers like [2,0,0,4] to
> [2,4,0,0]
> i come up with this code but in this code variable list is changing. i am
> unable to understand why ?
>
> list = [4,0,0,4]
>
> def re_sort(list):
>     count=0
>     tmp_list = list
>     print list
>     for i in list:
>         if not i:
>             tmp_list.remove(i)
>             count+=1
>     print list
>     for n in range(count):
>         tmp_list.append(0)
>     return tmp_list
> re_sort(list)
>
> ************************
> re_sort(list)
> [4, 0, 0, 4]
> [4, 0, 4]
> # Result: [4, 0, 4, 0] #
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/python_inside_maya/e4b95d9e-bda4-4499-9d94-
> 860be6aaaf5b%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/e4b95d9e-bda4-4499-9d94-860be6aaaf5b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



--

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPaTLMTEeEo2%3DuZ9m-Nv3eBsfWDmZAcNd_%2BYcKsE-yQDch49gA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to