Sort list from an index in Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Sort list from an index in Python

Hello I want to sort this list for start for example from 'D' and then finish to 'C#' element... It's Python language and I want to use index... scale = ['A','A#','B','C','C#','D','D#','E','F','F#','G#'] index = list.findindex('D')

29th Nov 2017, 6:26 AM
Matteo Pellegrini
Matteo Pellegrini - avatar
2 Answers
+ 4
Sounds like you can just use slices if I understand you correctly. scale = ['A','A#','B','B#','C','C#','D','D#','E','E#','F','F#','G#'] i = scale.index('D') l = scale[i:] + scale[:i] print(l) outputs: ['D', 'D#', 'E', 'E#', 'F', 'F#', 'G#', 'A', 'A#', 'B', 'B#', 'C', 'C#']
29th Nov 2017, 8:39 AM
ChaoticDawg
ChaoticDawg - avatar
29th Nov 2017, 7:01 AM
Amir Galanty
Amir Galanty - avatar