Bite 181. Keep a list sorted upon insert
Login and get codingComplete the
addmethod of theOrderedListclass which takes anumargument and adds that to theself._numbers listkeeping it ordered upon insert.Using a manual
.sort()or.sorted()each time is not allowed. Look into thebisectmodule how to do it ...Here is how it should works:
order = OrderedList() order.add(10) print(order) # __str__ already provided order.add(1) print(order) order.add(16) print(order) order.add(5) print(order)Output:
10 1, 10 1, 10, 16 1, 5, 10, 16Picking the right data structure is usually half of the battle. Good luck and keep calm and code more Python!
323 out of 324 users completed this Bite.
Will you be the 324th person to crack this Bite?
Resolution time: ~22 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 2.08 on a 1-10 difficulty scale.
» You can do it! 😌