I have two lists like
x = ['a', 'b', 'c', 'd'] and
y = [1, 2, 3, 4]
I have to create a dict from these two lists so that result is
{
'a': 1,
'b': 2,
'c': 3,
'd': 4
}
I do it using the following
dict(zip(x, y))
Is there a better and fast/efficient way of doing it?
I have to perform this operation on [m, b]illion of times and on different lists
Thank you
Per Praveen Gollakota’s comment, the original method will work fine. In Python 2.x, you can also use the izip function in the
itertoolsmodule. Either of these methods will work:In Python 3.x,
zipreturns an iterator by default, so this method will work perfectly: