Im new to python so I apologize in advance if this is a bit rudimentary, but given the list:
lst = ['user1', 25, 'user2', 10, 'user3', 54]
how would I create a dictionary that would be:
usr_dict = {'user1': 25, 'user2': 10, 'user3': 54]
This has already been answered here.
But here is a method that is a little easier to understand:
usr_dict = {}
for i in range(0, len(lst), 2):
usr_dict[lst[i]] = lst[i + 1]
I think the best approach is a dict comprehension:
usr_dict = {x[::2]:x[1::2] for x in lst}