Question: keyboard = { ' Q ' : ( 0 , 0 ) , ' W ' : ( 0 , 1 ) , ' E
keyboard Q: W: E: R: T: Y: U: I: O: P: A: S: D: F: G: H: J: K: L: Z: X: C: V: B: N: M: def getDistanceword: totaldistance currentpos keyboardQ # Start position at Q # Calculate the total distance for every character in the word. for char in word: nextpos keyboardchar # Get coordinates of the next character. # Calculate Manhattan distance between current and next position. distance abscurrentpos nextpos abscurrentpos nextpos totaldistance distance # Add to total distance. currentpos nextpos # Update current position. return totaldistance
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
