I want to get a dictionary from an available numeric list, divided by digits and their number in a string.
My inputs:
num_list = list('181986336314')
I need to get a dictionary like this:
mydict = {1: 111, 2: None, 3: 333, 4: 4, 5: None, 6: 66, 7: None, 8: 88, 9: 9}
>Solution :
One way to do it is to post engineer your counter result
counter = Counter(num_list)
my_dict = {}
for i in range(1, 10):
if (str(i) in counter.keys()):
my_dict[i] = int(str(i) * counter[str(i)])
else:
my_dict[i] = None
print(my_dict)
> {1: 111, 2: None, 3: 333, 4: 4, 5: None, 6: 66, 7: None, 8: 88, 9: 9}