python - What is an efficient data structure to store multiple variable-sized sets of numbers? -
i have multiple sets of numbers, so:
set 1: 1,2,3,5,4,3,2,1
set 2: 1,2,1,1
set 3: 1,1,1,0
set 4: 1,9
the number of sets specified user, , how many numbers each set may contain. then, program randomly populate values.
right now, using 2d array dimensions
[maximum(set-sizes)][maximum(elements_in_set)]
and setting unused cells large negative number indicate not of use. although serves purpose, wondering if there better data structure can use.
you can create list of lists:
>>> numbers = [ ... [1, 2, 3, 5, 4, 3, 2, 1], ... [1, 2, 1, 1], ... [1, 1, 1, 0], ... [1, 9] ... ] >>> numbers[3] [1, 9]
note describe not sets, because have no order , can contain every element once.
Comments
Post a Comment