• Google

    How is this code working? /Link




    I wrote this code for my homework:

    def find_all_modes(L):
    mode = {}
    modeCount = 1
    for i in range(1, len(L)):
    modeCount += 1
    if i == (len(L) - 1):
    mode.update({L[i - 1]: modeCount})
    if L[i] != L[i - 1]:
    mode.update({L[i - 1]: modeCount})
    modeCount = 1
    max_value = max(mode.values()) # maximum value
    max_keys = [key for key, value in mode.items() if value == max_value] # getting all keys containing the \maximum` return max_keys`

    I understand everything except for this line:

    max_keys = [key for key, value in mode.items() if value == max_value]

    I know what it is doing, but not how it is working - Can someone walk me through it?

    submitted by /u/teamomivida
    [link] [comments]



    (@)/u/teamomivida

    Published on 21 Oct 2018 at 03:20AM



















  • Recent Posts








    ^Comments