Fill the data of an Association based on a list
Another way (assuming that the keys are ordered)
AssociationThread[list1 -> Catenate[MapThread[ConstantArray,
{Values[asc], Differences[Prepend[Keys[asc], 0]]}]]]
<|1 -> a, 2 -> b, 3 -> b, 4 -> b, 5 -> c, 6 -> c, 7 -> c, 8 -> d, 9 -> d, 10 -> d|>
Piecewise
does what you need and here is a readable way to use it:
AssociationMap[
Evaluate[
Piecewise[KeyValueMap[Function[{k, v}, {v, # <= k}], asc]]
] &
, list1
]
Table[i -> asc[NestWhile[# + 1 &, i, ! MemberQ[Keys[asc], #] &]], {i,list1}] // Association
(* <|1 -> a, 2 -> b, 3 -> b, 4 -> b, 5 -> c, 6 -> c, 7 -> c, 8 -> d, 9 -> d, 10 -> d|> *)