Skip to content

Instantly share code, notes, and snippets.

@junhoyeo
Last active December 12, 2018 13:20
Show Gist options
  • Save junhoyeo/7a43dc8c59d8bf2a3f3b9b5ee3fd9e59 to your computer and use it in GitHub Desktop.
Save junhoyeo/7a43dc8c59d8bf2a3f3b9b5ee3fd9e59 to your computer and use it in GitHub Desktop.
JSON 문서 안 names 리스트의 정보 (지인분 도움)
import json
with open('something.json', 'r') as f:
data = json.load(f)
print(len(data['names'])) # 전체 names 리스트의 길이
kinds = []
for name in data['names']:
if name not in kinds:
print(name, data['names'].count(name)) # names 안의 한 name과 그 개수
kinds.append(name)
print(*kinds) # names 리스트에 있는 모든 name의 종류
@junhoyeo
Copy link
Author

junhoyeo commented Nov 4, 2018

실행결과 예시

something.json

{
    "names" : [
        "Mv1",
        "Mv1",
        "Mv2"
    ]
}

실행결과

3
Mv1 2
Mv2 1
Mv1 Mv2
  • `3 : 전체 names 리스트의 길이
  • Mv1 2: Mv1은 2개 발견
  • Mv2 1: Mv2는 1개 발견
  • Mv1 Mv2: names 리스트 안에 있는 모든 name 종류(Mv1, Mv2의 2가지)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment