Talk:Sort disjoint sublist: Difference between revisions

(→‎Indices as collection: duplicates - confirmed don't matter.)
Line 15:
 
:::::I confirmed that the Python-type algo's aren't upset by repeated terms - it just gives rise to extra, redundant work. You do, however have to eventually sort the indices and I think that this should be part of any correct answer that uses this type of algorithm rather than the Go-type algo. But even if duplicates did matter, I would read the task as ''not'' giving you duplicates. --[[User:Paddy3118|Paddy3118]] 19:49, 14 February 2011 (UTC)
 
::::::Yes they are:
::::::<lang python>>>> def sort_disjoint_sublist(data, indices):
... indices = sorted(indices)
... values = [data[i] for i in indices]
... values.sort()
... for index, value in zip(indices, values):
... data[index] = value
...
>>> d = [7, 6, 5, 4, 3, 2, 1, 0]
>>> i = [6, 1, 7, 7]
>>> sort_disjoint_sublist(d, i)
>>> d
[7, 0, 5, 4, 3, 2, 0, 6]</lang>
::::::--[[User:Rdm|Rdm]] 20:05, 14 February 2011 (UTC)
6,962

edits