Python Forum
Can a dictionary key be an integer?
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can a dictionary key be an integer?
#6
import openpyxl
xls_in='in.xlsx'
xls_out='out.xlsx'

wb1 = openpyxl.load_workbook(xls_in) 
active_sheet_wb1 = wb1.active
max_row = active_sheet_wb1.max_row 
 
students_and_scores = {}
for row_num in range(2, max_row +1):
    key = active_sheet_wb1.cell(row=row_num, column=2).value
    students_and_scores[key] = active_sheet_wb1.cell(row=row_num, column=1).value

wb2 = openpyxl.load_workbook(xls_out)
active_sheet_wb2 = wb2.active #get_sheet_by_name(sheetNameswb2[0])
max_row2 = active_sheet_wb2.max_row

for row_num in range(2, max_row + 1): 
    key = active_sheet_wb2.cell(row=row_num, column=1).value
    value = students_and_scores.get(key,'')
    active_sheet_wb2.cell(row=row_num, column=4, value=value)
 
wb2.save('try.xlsx')
this is minimal working script, tested by me. feel free to modify it.
Reply


Messages In This Thread
Can a dictionary key be an integer? - by Pedroski55 - Sep-27-2017, 05:20 AM
RE: Can a dictionary key be an integer? - by buran - Sep-27-2017, 05:53 AM
RE: Can a dictionary key be an integer? - by buran - Sep-28-2017, 01:29 PM
RE: Can a dictionary key be an integer? - by buran - Sep-30-2017, 02:23 PM
RE: Can a dictionary key be an integer? - by buran - Oct-05-2017, 05:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Replacing an integer by looking at a dictionary wendysling 3 2,384 May-02-2019, 03:38 PM
Last Post: wendysling

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020