About the difference between sorted and sorted in python. Both are algorithms that sort in ascending order.
Is the difference destructive?
sort: Destructive (the original data changes) sorted: Do not destroy (original data remains)
python
#In case of sort
a = [2,3,4,5,1]
a.sort()
print(f'a:{a}')
#a:[1, 2, 3, 4, 5]
sort changes the original data itself.
python
#In case of sorted
b = [2,3,4,5,1]
c = sorted(b)
print(f'b:{b}')
print(f'c:{c}')
#b:[2, 3, 4, 5, 1]
#c:[1, 2, 3, 4, 5]
In sorted, the original data remains the same.
Jupyter Notebook is also convenient, but it takes time to install. Colaboratory is easy because it just opens the page.
https://colab.research.google.com/notebooks/welcome.ipynb?hl=ja
・ Create a new notebook
・ You can add codes and text boxes with + at the top of the screen.
Code execution is Shift + Enter
You can share it with other people as well as Spushi. It is convenient to be able to write a comment in the box.
Recommended Posts