<jupyter_start><jupyter_text>Exercise 1.2.2- Print the first 3 lines from each `.gff3` file in the `data` folder.You may wish to use the `enumerate` function, along with the `break` statement to avoid printing every line in the file.<jupyter_code>import os
# os.chdir changes the working directory. Here we use ../ to go up one directory, out of the solutions directory
if os.getcwd().split('/')[-1] == 'solutions':
    os.chdir('../')
# go through all the files in the directory
for file_name in os.listdir('data'):
    
    # only do anything with files of the right type
    if file_name.endswith('.csv'):
        if not os.path.isdir('data/'+file_name):
            print(file_na)
            
            # print the first 3 lines
            with open('data/'+file_name) as f:
                print(file_name)
                # line_idx is the number of the line we are on
                for line_idx, line in enumerate(f):
                    print(line.strip())
                    if line_idx == 3:
                        break
                
                # print some blank lines so we can see what is happening
                print('\n\n')<jupyter_output>gapminder_gdp_americas.csv
continent,country,gdpPercap_1952,gdpPercap_1957,gdpPercap_1962,gdpPercap_1967,gdpPercap_1972,gdpPercap_1977,gdpPercap_1982,gdpPercap_1987,gdpPercap_1992,gdpPercap_1997,gdpPercap_2002,gdpPercap_2007
Americas,Argentina,5911.315053,6856.856212,7133.166023,8052.953021,9443.038526,10079.02674,8997.897412,9139.671389,9308.41871,10967.28195,8797.640716,12779.37964
Americas,Bolivia,2677.326347,2127.686326,2180.972546,2586.886053,2980.331339,3548.097832,3156.510452,2753.69149,2961.699694,3326.143191,3413.26269,3822.137084
Americas,Brazil,2108.944355,2487.365989,3336.585802,3429.864357,4985.711467,6660.118654,7030.835878,7807.095818,6950.283021,7957.980824,8131.212843,9065.800825



gapminder_gdp_europe.csv
country,gdpPercap_1952,gdpPercap_1957,gdpPercap_1962,gdpPercap_1967,gdpPercap_1972,gdpPercap_1977,gdpPercap_1982,gdpPercap_1987,gdpPercap_1992,gdpPercap_1997,gdpPercap_2002,gdpPercap_2007
Albania,1601.056136,1942.284244,2312.888958,2760.196931,3313.422188,3533.00391[...]<jupyter_text>Jupyter has the ability to execute Bash commands using `!`. These can be mixed with python code, so the above task can be completed with the following code:<jupyter_code># bash commands can create python objects, here `ls` creates a list of strings
csv_files = !ls data/*.csv

for file_name in csv_files:
    print(file_name)
    if not os.path.isdir(file_name):
        # python variables can be passed to bash using the $var syntax
        !head -3 $file_name
        !echo ""
!head -3 data/gapminder.csv<jupyter_output>country,continent,year,lifeExp,pop,gdpPercap
Afghanistan,Asia,1952,28.801,8425333,779.4453145
Afghanistan,Asia,1957,30.332,9240934,820.8530296
Afghanistan,Asia,1962,31.997,10267083,853.10071
Afghanistan,Asia,1967,34.02,11537966,836.1971382
Afghanistan,Asia,1972,36.088,13079460,739.9811058
Afghanistan,Asia,1977,38.438,14880372,786.11336
Afghanistan,Asia,1982,39.854,12881816,978.0114388
Afghanistan,Asia,1987,40.822,13867957,852.3959448
Afghanistan,Asia,1992,41.674,16317921,649.3413952
{'fraction_non_alphanumeric': 0.10587133041848844, 'fraction_numerical': 0.23672704559650218, 'mean_word_length': 4.3561872909699, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '534801', 'license': 'Unlicense', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1225, 'n_words': 211, 'path': 'solutions/ex_12_2.ipynb', 'repo_name': 'pycam/python-data-science', 'size': '3202'}