What is the best way to copy a list?

What is the best way to copy a list? I know the following ways, which one is better? Or is there another way? lst = ['one', 2, 3] lst1 = list(lst) lst2 = lst[:] import copy lst3 = copy.copy(lst) Answers: Thank you for visiting the Q&A section on Magenaut. Please note that all the answers … Read more

How to bind a click event to a Canvas in Tkinter?

In this example, we use the bind method of the frame widget to bind a callback function to an event called . Run this program and click in the window that appears. Each time you click, a message like “clicked at 44 63” is printed to the console window. Keyboard events are sent to the widget that currently owns the keyboard focus. You can use the focus_set method to move focus to a widget:

Using .pth files

I am trying to make a module discoverable on a system where I don’t have write access to the global site-packages directory, and without changing the environment (PYTHONPATH). I have tried to place a .pth file in the same directory as a script I’m executing, but it seems to be ignored. E.g., I created a file extras.pth with the following content:

What does hash do in python?

I saw an example of code that where hash function is applied to a tuple. As a result it returns a negative integer. I wonder what does this function do? Google does not help. I found a page that explains how hash is calculated but it does not explain why we need this function.