I have a list which looks something like this
List = [q1,a1,q2,a2,q3,a3]
I need the final code to be something like this
dictionary = {q1:a1,q2:a2,q3:a3}
if only I can get values at a certain index e.g List[0] I can accomplish this, is there any way I can get it?
Python dictionaries can be constructed using the
dictclass, given an iterable containing tuples. We can use this in conjunction with therangebuiltin to produce a collection of tuples as in (every-odd-item, every-even-item), and pass it todict, such that the values organize themselves into key/value pairs in the final result: