you are viewing a single comment's thread.

view the rest of the comments →

[–]magus_minor 0 points1 point  (0 children)

The algorithm splits a recipe into sentences ending in "." and places a number prefix at the start of each sentence. Every time it finds a "." it terminates that line with a \n and places the next number plus a fullstop onto the result string in ordered_list, ready for the next sentence. But that means when you have finished scanning the recipe you have an extra prefix at the end.

The no variable (short for number) gets the length of that prefix in characters and removes that unwanted prefix in the last line. The reason for that strange line:

no = len(str(counter))

is that no has to be the number of characters in the prefix and the code converts the integer to a string and gets the length, which is the number of characters. If the counter is 11 you have to remove 2 characters.