문제링크: 달리기 경주
✍🏻 Information
| content | |
|---|---|
| 언어 | python |
| 난이도 | ⭐️⭐️+(0.5) |
| 풀이시간 | 30분 |
| 제출횟수 | 多 |
| 인터넷검색유무 | yes |
🍒 My Code
def solution(players, callings):
_players={}
for idx, player in enumerate(players):
_players[player]=idx
for calling in callings:
#idx = players.index(calling)
idx = _players[calling]
_players[players[idx-1]], _players[players[idx]]= _players[players[idx]],_players[players[idx-1]]
players[idx], players[idx-1]= players[idx-1],players[idx]
return players
💡 What I learned
list_name.index(찾고싶은내용)numpy.where 사용def solution(players, callings):
answer = players
times = []
for player in players:
times.append(callings.count(player))
for idx in range (len(players)):
answer[idx],answer[idx-times[idx]]=answer[idx-times[idx]],answer[idx]
return answer
뛰어난 글이네요, 감사합니다.