FASTA-to-tsv conversion script I worked on a script that takes as input a multi-sequence .fasta file and outputs the number of each aminoacid/sequence in a .tsv format.
This is how a .fasta file looks:
&gt;sp|P21515|ACPH_ECOLI Acyl carrier protein phosphodiesterase OS=Escherichia coli (strain K12) OX=83333 GN=acpH PE=1 SV=2 
MNFLAHLHLAHLAESSLSGNLLADFVRGNPEESFPPDVVAGIHMHRRIDVLTDNLPEVREAREWFRSETRRVAPITLDVMWDHFLSRHWSQLSPDFPLQEFVCYAREQVMTILPDSPPRFINLNNYLWSEQWLVRYRDMDFIQNVLNGMASRRPRLDALRDSWYDLDAHYDALETRFWQFYPRMMAQASRKAL

I know there are libraries which do the same thing, however, I had to write this script as a homework, without the help of BioPython or other similar libraries.
My question is: how can I make this code more efficient?
import sys
import os


def readFasta( path ):
    
    seq = { }
    aCount = { }
    alphabet = &quot;ABCDEFGHIJKLMNOPQRSTUVWYZX*-&quot;  

    for fileName in path:
        
        with open( fileName ) as file:
            fastaLine = file.readlines( )
            
            # sequence storage
            
            for line in fastaLine:
                if line[ 0 ] == &quot;&gt;&quot; :
                    headerTitle = line.split( &quot;|&quot; )[ 1 ]
                    seq[ headerTitle ] = &quot;&quot;
                else:
                    seq[ headerTitle ] += line.strip( )

            # aminoacid count

            for id in seq:
                aCount[ id ] = { }
                for sequence in seq[ id ]:
                    if sequence not in alphabet:
                        print( &quot;Check your sequence! Character: &quot; + str(sequence) + &quot; from sequence: &quot; + id )
                    for letter in alphabet:
                        aCount[ id ][ letter ] = 0
            
            # count aminoacid occurence/sequence
            
            for name in seq:
                for char in seq[ name ]:
                    if char in aCount[ name ]:
                        aCount[ name ][ char ] += 1
    
    # write to .csv file
    
    outFile = open( &quot;output.csv&quot; , &quot;w&quot; )
    
    
    outFile.write( &quot;Name&quot; + '\t' )
    
    header = &quot;&quot;
    for letter in alphabet:
        header += letter + '\t'

    outFile.write( header + &quot;Total&quot; )
    outFile.write( '\n' )          
    
    for name in aCount:
        entry = &quot;&quot;
        counter = 0
        for letter in aCount[ name ]:
            entry += str(aCount[ name ][ letter ]).strip( ) + '\t'
            counter += aCount[ name ][ letter ]
        outFile.write( name + '\t' + entry + '\t' + str( counter ) )
        outFile.write( '\n' )

# files to list

entries = os.listdir( path )

# filter for .fasta/.fa files

new_list = [ ]
for entry in entries:
    if &quot;.fasta&quot; in entry:
        new_list.append( entry )
    elif &quot;.fa&quot; in entry:
        new_list.append( entry )
        
# execute func

readFasta( new_list )
Welcome to Code Review!
I'll add to the other answer from Reinderien.
PEP-8
In python, it is common (and recommended) to follow the PEP-8 style guide for writing clean, maintainable and consistent code.
Functions and variables should be named in a lower_snake_case, classes as UpperCamelCase, and constants as UPPER_SNAKE_CASE.
No unnecessary whitespaces are needed around the arguments when defining or calling a function. This applies for referring array/list elements as well.
Functions
Split your code into individual smaller functions, doing singular tasks. A few examples would be, reading/parsing the fasta files, validating sequence of gene, counting occurrences (try collections.Counter package to do this).
CSV/TSV
Python comes with inbuilt package csv which can also be used to write tsv files. You do not need to modify/write each line yourself.
Glob searching for files
Python 3+ has another inbuilt package pathlib, which supports getting all files using a glob pattern. You would again, not need to manually (metaphorically) aggregate all the files with .fa or .fasta extensions.
if __name__ block
For scripts, it is a good practice to put your executable feature inside the if __name__ == &quot;__main__&quot; clause.