queryInclude,yahoo,value1
queryInclude,yahoo,value2
queryInclude,yahoo,value3
queryExclude,yahoo,value4
queryExclude,yahoo,value5
queryInclude,google,value6
queryExclude,google,value7
내 이상적인 결과가 [0] = 사전, 행 [1] = 키 행이 있고, [2] =을 행 것이다 파이썬에서 여러 사전에 CSV를 가져올 값 또는 값
queryInclude = {
"yahoo": ["value1", "value2", "value3"],
"google": ["value6"] }
queryExclude = {
"yahoo": ["value4", "value5"],
"google": ["value7"] }
여기 내 코드의 목록 :
import csv
queryList=[]
queryDict={}
with open('dictionary.csv') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in reader:
queryDict[row[1]] = queryList.append(row[2])
print queryDict
{'yahoo': None}
{'yahoo': None}
{'yahoo': None}
{'yahoo': None}
{'yahoo': None}
{'google': None, 'yahoo': None}
{'google': None, 'yahoo': None}
내가 필요한 경우 CSV 형식을 변경 할 수있는 유연성을 가지고있다. 위에 게시 한 나의 이상적인 결과는 이미 내 앱에 하드 코딩 된 것입니다. 길 아래에 더 많은 가치를 더 쉽게 추가하려고 노력 중입니다. 나는 이것을 연구하는 데 많은 시간을 할애했으며, 더 나아질 경우 계속 업데이트 할 것입니다. 내 생각 과정이 도움의이
for row in reader:
where row[0] = queryInclude:
create a dictionary combining keys into a list of values
where row[0] = queryExclude:
create a dictionary combining keys into a list of values
이 매우 도움이 키가 아닌 기본 객체를 생성하는 호출해야 할 때 기본 유형을 선언합니다. 도와 줘서 고마워! – Jared