Вопрос

I am using a dictionary comprension to be created from an excel spreadsheet. The first column of the excel sheet are the keys and the next 3 columns are the values. I'd like to build a dictionary comprehension that I can use later in my script. I understand a dictionary comprehension to be built as:

d = {key: value for (key, value) in sequence}

and I can do this and get a nice key,value dictionary:

d = {str(row.getValue("Column1")): str(row.getValue("Column2")) for i in arcpy.SearchCursor(xls,"[Column1] = 'Lake_Huron'")}

I'm just not sure how I would go about adding the other 2 columns in the dictionary comprehension as 2nd and 3rd values to the key? Is this possible?

Это было полезно?

Решение

d = {str(row.getValue("Column1")): (str(row.getValue("Column2")), str(row.getValue("Column3")), str(row.getValue("Column4"))) for i in arcpy.SearchCursor(xls,"[Column1] = 'Lake_Huron'")}

OR

d = {str(row.getValue("Column1")): (str(row.getValue("Column{0}".format(i)) for i in [2, 3, 4]) for i in arcpy.SearchCursor(xls,"[Column1] = 'Lake_Huron'")}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top