Question about a solution that I found.

  • 0

    Re: Time Limit Exceeded with my python code
    I came across this answer while looking through the discussion for the 2sum question.

    I get that d is a dictionary, but could someone explain exactly what is being done in the lines
    d = {n:pos for pos,n in enumerate(num) }
    for i,n in enumerate(num):

    I get essentially that they are creating a dictionary of all the elements in the list and that its iterating through the dict but I dont fully understand definition of the dict or the for loop. Are these just a shorter way of creating them? and if so what would they look like in a "long hand" definition?

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.