I need to write a function that creates a list of tuples of the first occurrence of a letter followed by its row and column in a list of lists.
Example Input and Output:
lot2 = [['.','M','M','H','H'],
#Output: [('M', 0, 1), ('H', 0, 3), ('f', 1, 4), ('B', 2, 0)]
letter = '.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
for y, row in enumerate(lst):
if letter in row:
return letter, y, row.index(letter)
First off, use the string library to get a string of all upper and lower case letters:
import string string.ascii_letters Out: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' collector =  output_list =  for i in lot2: for j in i: if j in string.ascii_letters and j not in collector: tmp = (j,lot2.index(i), i.index(j)) output_list.append(tmp) collector.append(j)
output_list should give you what you want.
edit: If you want to also capture full-stops use string.printable - although this will give you a string that consists of additional punctuation and white space characters as well.