for event in pygame event get(keyup)get all the keyup events if event key =k_escapeterminate(terminate if the keyup event was for the esc key pygame event post(eventput the other keyup event objects back the checkforquit(function will check for quit events (or if the user has pressed the esc keyand then call the terminate(function but this is bit tricky and requires some explanation pygame internally has its own list data structure that it creates and appends event objects to as they are made this data structure is called the event queue when the pygame event get(function is called with no parametersthe entire list is returned howeveryou can pass constant like quit to pygame event get(so that it will only return the quit events (if anythat are in the internal event queue the rest of the events will stay in the event queue for the next time pygame event get(is called you should note that pygame' event queue only stores up to event objects if your program does not call pygame event get(frequently enough and the queue fills upthen any new events that happen won' be added to the event queue line pulls out list of quit events from pygame' event queue and returns them if there are any quit events in the event queuethe program terminates line pulls out all the keyup events from the event queue and checks if any of them are for the esc key if one of the events isthen the program terminates howeverthere could be keyup events for keys other than the esc key in this casewe need to put the keyup event back into pygame' event queue we can do this with the pygame event post(functionwhich adds the event object passed to it to the end of the pygame event queue this waywhen line calls pygame event get(the non-esc key keyup events will still be there otherwise calls to checkforquit(would --consume|all of the keyup events and those events would never be handled the pygame event post(function is also handy if you ever want your program to add event objects to the pygame event queue creating the board data structure def getstartingboard() return board data structure with tiles in the solved state for exampleif boardwidth and boardheight are both this function returns [[ ][ ][ none] counter