sort array from 1 to n python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

sort array from 1 to n python

how we can sort array from 1 to n python not from 0 to n Start from index 1 For example a = np.array([ 1 , 2 , 3]) not a[0] == 1 i want that index starts from 1 a [1] == 1

15th Apr 2021, 10:16 AM
nima rasi
4 Answers
0
You can do this sorted_list = sorted(old_list[1:]) This way will not include the 0 index element though, so you need to add back if required
15th Apr 2021, 10:19 AM
Hoh Shen Yien
Hoh Shen Yien - avatar
0
thanks but i want a array not a list
15th Apr 2021, 10:20 AM
nima rasi
0
It's the same, you can try it your own
15th Apr 2021, 10:24 AM
Hoh Shen Yien
Hoh Shen Yien - avatar
0
Arrays start from 0. That's just a fundamental fact. If you want an indexed list that doesn't use array rules, you want to use a dictionary. i = 1 fake_array = {} for num in num_list = [1, 2, 3]: fake_array[i] = num i += 1 fake_array[1] == 1 #will be True
15th Apr 2021, 10:54 PM
Myk Dowling
Myk Dowling - avatar