"""
CP1404/CP5632 Practical
List comprehensions
"""

names = ["Bob", "Angel", "Jimi", "Alan", "Ada"]
full_names = ["Bob Martin", "Angel Harlem", "Jimi Hendrix", "Alan Turing",
              "Ada Lovelace"]

# for loop that creates a new list containing the first letter of each name
first_initials = []
for name in names:
    first_initials.append(name[0])
print(first_initials)

# list comprehension that does the same thing as the loop above
first_initials = [name[0] for name in names]
print(first_initials)

# list comprehension that creates a list containing the initials
# splits each name and adds the first letters of each part to a string
full_initials = [name.split()[0][0] + name.split()[1][0] for name in
                 full_names]
print(full_initials)

# one more example, using filtering to select only the names that start with A
a_names = [name for name in names if name.startswith('A')]
print(a_names)

# TODO: use a list comprehension to create a list of all of the full_names in lowercase format
lowercase_full_names = [name.lower() for name in full_names]
print(lowercase_full_names)

almost_numbers = ['0', '10', '21', '3', '-7', '88', '9']
# TODO: use a list comprehension to create a list of integers from the above list of strings
numbers = [int(number) for number in almost_numbers]
print(numbers)

# TODO: use a list comprehension to create a list of only the numbers that are
# greater than 9 from the numbers (not strings) you just created
greater_than_9 = [number for number in numbers if number > 9]
print(greater_than_9)

#List of numbers that are divisible by 3
divisible_3 = [number for number in numbers if number%3 == 0]
print(divisible_3)

#list of numbers to the 2nd power
squares_list = [number**2 for number in numbers]
print(squares_list)

#list of numbers that have 1 in them using string number list
one_in_list = [number for number in almost_numbers if '1' in number]
print(one_in_list)

#list of odd numbers in list
odd_nums = [number for number in numbers if number %2 == 1]
print(odd_nums)

#list of even numbers in list
even_nums = [number for number in numbers if number%2 == 0]
print(even_nums)

#list of names that have an 'e' in their name
e_in_name = [name for name in full_names if 'e' in name]
print(e_in_name)

