Created
August 1, 2025 01:22
-
-
Save RichardLitt/a3b72a13258ef00d796f5fc075ebec2e to your computer and use it in GitHub Desktop.
How I get every file that ends in E
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import csv | |
| # Specify the file name | |
| # This file is 33,0000 lines long! | |
| file_name = 'clements.csv' | |
| # List to store the extracted genera | |
| genera = [] | |
| # Open the CSV file | |
| with open(file_name, newline='', encoding='utf-8') as csvfile: | |
| reader = csv.DictReader(csvfile) # Use DictReader to read CSV into a dictionary format | |
| for row in reader: | |
| scientific_name = row['scientific name'] | |
| # Check if the scientific name ends with 'e' | |
| print(scientific_name) | |
| if scientific_name: | |
| genus = scientific_name.split()[0] | |
| if genus.endswith('e') and not genus.endswith('idae'): | |
| # Split the scientific name to get the genus | |
| genera.append(genus) | |
| # Sort and remove duplicates | |
| unique_genera = sorted(set(genera)) | |
| # Print the genera | |
| for genus in unique_genera: | |
| print(genus) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment