I am new at using python and am trying to get my code to use a list I pulled from an excel sheet (using openpyxl). I created a dict that stored these letters as keys(letter) with associated values(word). I want to use the value returned in the list to check that against the dictionary key(letter) to pull the matching value(word). I then hope to take the value(word) and add it to a column in my excel sheet. I am stuck on how to do this last part.
# Open excel document with OpenPyXL and define Sheet1 as ws, Sheet2 as ws2.
import openpyxl
wb = openpyxl.load_workbook('example.xlsx')
ws = wb.worksheets[0]
ws2 = wb.worksheets[1]
# create a mapping of first letter to word
letter_word = {
'Q': 'Quick',
'J': 'Jump',
'P': 'Pass',
}
print(letter_word) # print to check it is working
# look at excel worksheet 1 and list all values in the A column by the 1st letter
first_letter = []
for x in range(2, ws.max_row+1):
first_char = ws.cell(row=x, column=1).value[0]
first_letter.append(first_char)
print(first_letter) # print to check it is working output is ['Q', 'P','J']