<jupyter_start><jupyter_text>Writing a generator to load data in chunks (3)Great! You've just created a generator function that you can use to help you process large files.Now let's use your generator function to process the World Bank dataset like you did previously. You will process the file line by line, to create a dictionary of the counts of how many times each country appears in a column in the dataset. For this exercise, however, you won't process just 1000 rows of data, you'll process the entire dataset!The generator function read_large_file() and the csv file 'world_dev_ind.csv' are preloaded and ready for your use. Go for it! Instructions- Bind the file 'world_dev_ind.csv' to file in the context manager with open().- Complete the for loop so that it iterates over the generator from the call to read_large_file() to process all the rows of the file.<jupyter_code>def read_large_file(file_object):
    """A generator function to read a large file lazily."""

    # Loop indefinitely until the end of the file
    while True:

        # Read a line from the file: data
        data = file_object.readline()

        # Break if this is the end of the file
        if not data:
            break

        # Yield the line of data
        yield data
# Initialize an empty dictionary: counts_dict
counts_dict = {}

# Open a connection to the file
with open ('world_ind_pop_data.csv') as file:

    # Iterate over the generator from read_large_file()
    for line in read_large_file(file):

        row = line.split(',')
        first_col = row[0]

        if first_col in counts_dict.keys():
            counts_dict[first_col] += 1
        else:
            counts_dict[first_col] = 1

# Print            
print(counts_dict)<jupyter_output>{'CountryName': 1, 'Arab World': 55, 'Caribbean small states': 55, 'Central Europe and the Baltics': 55, 'East Asia & Pacific (all income levels)': 55, 'East Asia & Pacific (developing only)': 55, 'Euro area': 55, 'Europe & Central Asia (all income levels)': 55, 'Europe & Central Asia (developing only)': 55, 'European Union': 55, 'Fragile and conflict affected situations': 55, 'Heavily indebted poor countries (HIPC)': 55, 'High income': 55, 'High income: nonOECD': 55, 'High income: OECD': 55, 'Latin America & Caribbean (all income levels)': 55, 'Latin America & Caribbean (developing only)': 55, 'Least developed countries: UN classification': 55, 'Low & middle income': 55, 'Low income': 55, 'Lower middle income': 55, 'Middle East & North Africa (all income levels)': 55, 'Middle East & North Africa (developing only)': 55, 'Middle income': 55, 'North America': 55, 'OECD members': 55, 'Other small states': 55, 'Pacific island small states': 55, 'Small states': 55, 'South Asia': 55, 'Sub-Sa[...]
{'fraction_non_alphanumeric': 0.0953243928959768, 'fraction_numerical': 0.024284160927872417, 'mean_word_length': 3.8421052631578947, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '61769', 'license': 'MIT', 'n_tokens_mistral': 853, 'n_tokens_neox': 752, 'n_words': 370, 'path': 'Python Data Science Toolbox -Part 2/Bringing it all together/07. Writing a generator to load data in chunks (3).ipynb', 'repo_name': 'nazmusshakib121/Python-Programming', 'size': '2759'}