Skip to content

Instantly share code, notes, and snippets.

@kkismd
Created August 27, 2019 06:02
Show Gist options
  • Save kkismd/2289ac59bb3a1cacffa366fa5dbef8cc to your computer and use it in GitHub Desktop.
Save kkismd/2289ac59bb3a1cacffa366fa5dbef8cc to your computer and use it in GitHub Desktop.
from typing import List
def parseInt(input: str) -> List[int]:
try:
return [int(input)]
except ValueError:
return []
def findUser(code: int) -> List[dict]:
users = {
2012: {"id": 1, "code": 2012, "name": "yuzu"},
3308: {"id": 2, "code": 3308, "name": "yui"}
}
user = users.get(code)
if user:
return [user]
else:
return []
def findItem(userId: int) -> List[dict]:
items = {
1: {"userId": 1, "name": "keyboard"}
}
item = items.get(userId)
if item:
return [item]
else:
return []
keybord = [item["name"]
for code in parseInt("2012")
for user in findUser(code)
for item in findItem(user["id"])]
print(keybord) # => ['keyboard']
what = [item["name"]
for code in parseInt("WXYZ") # <- 失敗する
for user in findUser(code)
for item in findItem(user["id"])]
print(what) # => []
guitor = [item["name"]
for code in parseInt("3308")
for user in findUser(code)
for item in findItem(user["id"])] # <- 失敗する
print(guitor) # => []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment