Nếu nó không có trong từ điển, nó không thể được tìm thấy. Các dữ liệu trong từ điển row_data ban đầu đến từ các bảng tính và được đọc vào chương trình của bạn từ các tập tin CSV. Nếu giá trị dữ liệu được nhập vào biến recorded_time trong từ điển, mọi thứ sẽ là tốt, bởi vì có một trận đấu. | dealing with complexity If it s not in the dictionary it can t be found. The data in the row data dictionary originally comes from the spreadsheet and is read into your program from the CSV file. If the data value entered into the recorded time variable is in the dictionary things are going to be fine because there s a match. However if the data entered into the recorded time variable doesn t match anything in the dictionary you ll get a KeyError. But how is this problem handled during training If we have a match great. If not we look for the closest match and work from there. a 2Z k run ialls between -these -two values on -the pace sheet you are here 4 415 close enough Search for the closest match All you need to do is search the row of data for the closest match right And guess what The Head First Code Review Team think they have some functions that might help here. There s nothing better than sharing our code with our fellow Python programmers. Check out our find_it module. This Code is in 3 f e talleH FindlW and r tan download a tort tron W S book s suyyort website- Here s an exam e a hested Function which is allowed in Python. 4iven two values this Function returns the diFFerenCe between them. function does a simple linear search returning the value in target data that most closely matches the look_for argument- This may not be the most e-fiicient search Code ever written but it works. 416 Chapter 11 dealing with complexity Let s test the find_it. py module to try and determine if it meets the requirements of your application. Load the module into IDLE and then press F5 or choose Run Module from the Run menu find_closest 6 find_closest 3 1 5 6 1 find_closest 3 1 3 4 6 3 find_closest find_closest 3 1 4 6 4 6 4iven a value -to look tor and some target data the iind_ilosest Tunetion seems to be doing the triek. find_closest 6 Let s try it with some of data that more closely resembles your CSV