Why in the output I am getting value as list

Viewed 43

I have converted the nested loop into dictionary. Here is the nested list.

score = [['hamza', 30], ['ali', 20], ['abdul',50]]

I have converted this into dict with this code.

my_dict = { k[0]: k[1:] for k in score}

Here is the output.

{'hamza': [30], 'ali': [20], 'abdul': [50]}

Why in the values are inside the list.

Is there anyway to get the values without list.

1 Answers

Your syntax k[1:] means "Give me a list of all the elements in k, starting from element 1 and going all the way to the end".

Just leave the : away and you'll get what you want.

Related