samedi 29 octobre 2016

Python - How to print out all letters from a list

There are given lots and I'm suppose to print out all letters, either uppercase or lower case. I'm also not allowed to use any built in functions. I'm having difficult printing out the list of letters. All i get in return is an empty closed bracket.

alphabet = "abcdefghijklmnopqrstuvwxyz"

alphabet2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def get_symbols(lot):
list = []
for i in lot:
    if (i == alphabet or i == alphabet2):
        list.append(lot);
return list

The given lot:

lot1 = [['.', '.', 'a', 'D', 'D'],
       ['.', '.', 'a', '.', '.'],
       ['A', 'A', '.', 'z', '.'],
       ['.', '.', '.', 'z', '.'],
       ['.', '.', 'C', 'C', 'C']]

My output:

Traceback (most recent call last):
File "tester4p.py", line 233, in test_get_symbols_2
def test_get_symbols_2 (self): self.assertEqual (get_symbols(lot1()),['a','D','A','z','C'])
AssertionError: Lists differ: [] != ['a', 'D', 'A', 'z', 'C']

Second list contains 5 additional elements.
First extra element 0:
'a'

- []
+ ['a', 'D', 'A', 'z', 'C']

Expected Output:

['a', 'D', 'A', 'z', 'C']

Aucun commentaire:

Enregistrer un commentaire