""" Calculate percentage level of index for regions inside the Verenigde Nederlanden. """ REGIONS = [ 'Amsterdam', 'Northern Netherlands', 'Eastern Netherlands', 'Western Netherlands', 'Southern Netherlands', ] def region_in_string(string): """Look for region in string""" for region in REGIONS: if region in string: return True return False def calculate_index(): """Calculate index bases on file""" with open('regions.txt', 'r') as file: line_nr = 0 last_percentage = 11 for line in file: line_nr += 1 if region_in_string(line): percentage = 11 - 10 / 998 * line_nr diff_percentage = last_percentage - percentage last_percentage = percentage region = line.strip().split('\t') print('%40s %2s %6.2f %% %6.2f %%' % ( region[0], region[1], percentage, diff_percentage )) if __name__ == '__main__': calculate_index()