how do i jump or to shuffle the next value in a list? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how do i jump or to shuffle the next value in a list?

count = 0 # counter after the solution should be 7 a = ['1', '2', '3', '3', '5', '5', '6', '6', '7', '9'] # 5<->7 and 6<->9 b = ['0', '0', '2', '2', '3', '6', '6', '6', '7', '9'] count+=1 <<if a[i]>b[i] iterating through both the list together, whenever a[element]<b[element], i want to shuffle the current a[element] with a greater that is greater than the current b[element] too.. As in above case, a[elements] are greater than b[element] until a[5] comes during iteration, because a[5]<b[5]...so what i wanna do is find the next element in the "list a" which is greater than b[5] i.e 7..and shuffle 5 and 7 in the list 'a'.and comare with the current element in "list b"......and same for the further elements until list is over... and count+=1 when a[element]>b[element]... in the above case, count must be =7, because of shuffling 7 and 9 in "list a" hope you understand what i am trying to tell you!

13th Apr 2020, 6:02 PM
Amit Dubey
Amit Dubey - avatar
5 Answers
+ 1
@Amit Dubey I wrote it, but it is not a good idea to use it without understanding it. I put a lot of comment to help you to understand, so please take some time to do this :) https://code.sololearn.com/c4FZFwso93VZ/#py
14th Apr 2020, 8:25 AM
Gwlanbzh
Gwlanbzh - avatar
+ 1
So you want that a[i] > b[i], except for the last few elements ? So that in this case, a = [1, 2, 3, 3, 5, 7, 9, 5, 6, 6] If yes, I can help you, else, please help me to understand what you want first :)
13th Apr 2020, 6:19 PM
Gwlanbzh
Gwlanbzh - avatar
0
Kinda like that..but a lil change... a = ['1', '2', '3', '3', '5', '7', '9', '6', '5', '6']...put the element to be swapped i.e 5 at the place of 7..and 6 at the place of 9... SpaceNerd
13th Apr 2020, 6:37 PM
Amit Dubey
Amit Dubey - avatar
0
a = [1, 2, 3, 3, 5, 7, 9, 5, 6, 6] This can work too, i guess..gimme a code plz SpaceNerd
13th Apr 2020, 6:54 PM
Amit Dubey
Amit Dubey - avatar
0
Wow... that's some great explanatory skills you got! Thank you so much!😊 SpaceNerd
14th Apr 2020, 11:26 AM
Amit Dubey
Amit Dubey - avatar