A function that returns all letters in the Alphabet except the ones in a pre-defined list This function should return a string that is comprised from all the letters in the Alphabet except the letters in a pre-defined list in alphabetical order.

Assuming all letters in the pre-defined list are all lowercase;

I came up with two ways to do this and I would like to know which way is more efficient or more 'Pythonic'. 
Thanks in advance.

The first way:

import string

def get_remaining_letters(list_of_characters):
    # casting the Alphabet to a list so that it becomes mutable

    list_of_all_letters = list(string.ascii_lowercase)
# looping for each character in the pre-defined list
    for char in list_of_characters :
        if char in list_of_all_letters: # to avoid possible errors caused by the .remove in case of a duplicate charcter in the pre-defined list 
            list_of_all_letters.remove(char) 
    return ''.join(list_of_all_letters) # returns a string 

# ----------------------------------------------------------- #

pre_defined_list = ['a', 'b', 'b']

test = get_remaining_letters(pre_defined_list)
print(test)


output :

&gt;&gt;&gt; cdefghijklmnopqrstuvwxyz


The second way:

import string

def get_remaining_letters(list_of_characters):

    if list_of_characters == []:
        return string.ascii_lowercase
    else:
        remaining_letters = ''
        for char in string.ascii_lowercase:
            if char not in list_of_characters:
                remaining_letters += char
        return remaining_letters



pre_defined_list = ['a', 'b', 'b']


test = get_remaining_letters(pre_defined_list)
print(test)



output :

&gt;&gt;&gt; cdefghijklmnopqrstuvwxyz
I suggest you check PEP0008 https://www.python.org/dev/peps/pep-0008/ the official Python style guide and Flake8 http://flake8.pycqa.org/en/latest/ as a tool for style enforcement.


Docstrings: Python documentation strings or docstrings are a way of documenting your classes/function/modules and are usually accessed through help(). You should include docstrings to your functions indicating what they do and what they return.
Type hints: Type Annotations are a new feature added in PEP 484 that allow for adding type hints to variables. They are used to inform someone reading the code what the type of a variable should be. As you're taking a list as input and will return a string, you should have some documentation indicating that. Use type hints.

function should look like:

def get_remaining_letters(letters: list) -&gt; str:
    """Return lowercase alphabetic letters that are not present in letters."""

Blank lines: instead of this # ----------------------------------------------------------- # an empty line is sufficient and note that according to PEP0008 empty lines as well as comments should be used sparingly (when necessary) to separate logical sections as well as explain the not-so-obvious parts of the code.
main guard: use if __name__ == '__main__': guard at the end of the script to allow outside modules to import this module without running it as a whole. You will be calling your functions from there.

if __name__ == '__main__':
    pre_defined_list = ['a', 'b', 'b']
    test = get_remaining_letters(pre_defined_list)
    print(test)

Evaluation to empty list: In Python empty sequences evaluate to False.
instead of if list_of_characters == []: it is written: if not list_of_characters:
Adding to strings: Python strings are immutable which means that each time you're adding to a string like in remaining_letters += char a new string is created and assigned the new value which is inefficient and should be replaced with list comprehension syntax which is shorter and more efficient or Pythonic as you call it.

An improved version of the code:

import string


def get_remaining_letters(letters: list) -&gt; str:
    """Return lowercase alphabetic letters not present in letters."""
    return ''.join(letter for letter in string.ascii_lowercase if letter not in letters)


if __name__ == '__main__':
    chosen = [letter for letter in 'sdfmmmsvvd']
    print(get_remaining_letters(chosen))