다른 행의 값을 비교해야합니다. 각 행은 사전이고 인접한 행의 값을 키 '플래그'와 비교해야합니다. 어떻게하면 좋을까요? 간단히 말씀 : 'int' object is not subscriptable
범위는 INT의 목록을 반환하더라도중복 된 항목을 제거 하시겠습니까?
... 댓글
응답 : 행의
목록이입니다
for row in range(1,len(myjson))::
if row['flag'] == (row-1)['flag']:
print yes
는 형식 오류를 반환 사전 목록. 원래 탭으로 구분 된 파일을 가져 와서 csv.dict 모듈을 사용하여 읽었습니다. 변수 이름에 해당하는 키가있는 사전 목록이됩니다. 또한
{'website': '', 'phone': '', 'flag': 0, 'name': 'Diane Grant Albrecht M.S.', 'email': ''}
{'website': 'www.got.com', 'phone': '111-222-3333', 'flag': 1, 'name': 'Lannister G. Cersei M.A.T., CEP', 'email': '[email protected]'}
{'website': '', 'phone': '', 'flag': 2, 'name': 'Argle D. Bargle Ed.M.', 'email': ''}
{'website': 'www.daManWithThePlan.com', 'phone': '000-000-1111', 'flag': 3, 'name': 'Sam D. Man Ed.M.', 'email': '[email protected]'}
{'website': '', 'phone': '', 'flag': 3, 'name': 'Sam D. Man Ed.M.', 'email': ''}
{'website': 'www.daManWithThePlan.com', 'phone': '111-222-333', 'flag': 3, 'name': 'Sam D. Man Ed.M.', 'email': '[email protected]'}
{'website': '', 'phone': '', 'flag': 4, 'name': 'D G Bamf M.S.', 'email': ''}
{'website': '', 'phone': '', 'flag': 5, 'name': 'Amy Tramy Lamy Ph.D.', 'email': ''}
:
for row in myjson:
print row
출력 (myjson는 사전의 목록입니다) :
코드
type(myjson)
<type 'list'>
list_of_rows의 데이터 유형은 무엇입니까? – Sheng
'TypeError'를 얻는다면,'list_of_rows'는 사전을 포함하지 않을 것입니다. –
'TypeError'는 어떤 줄부터 시작됩니까? 나는'row'가'int' (계산은 성공하지만'int'는 subscriptable이 아님)를 의미하는'(row-1) [ 'flag']'라고 내기 때문에'list_of_rows'는 반복 가능합니다 ints의. –