filter(), lambda(), dictionary, sort()

https://py.checkio.org/en/mission/the-ship-teams/

# sorting the ship teams into 20<=x<=40 and the others.
# sorting by name in alphabetical order in each group.

# input : dictionary with the sailors and their ages.
# output : List of the lists with 2 teams.

example

아래 설명 보면 이해됨.

list(……) :  …. 결과물로 List를 만들어 team1, team2라는 리스트를 만듬

….부분중 filter(a:b) : iterable한 b의 element를 조건A에 넣어서 True일 경우만 골라 iterator를 만듬.

filter(a:b)에서 a부분인 lambda x: function : x를 function에 넣어서 결과물을 반환

sort() : 정렬

 

filter(function, list)

The filter() function returns an iterator were the items are filtered through a function to test if the item is accepted or not.fliter1

lambda

lambda args : expression  형태

lamda

 

dictionary에서 list(dic_name)하면 keys 반환

list of dictionary

 

Dictionary는 iterable하니 루프돌릴수 있음.

x 와 dictionary[x] 를 구별해서 사용

x는 keys

dictionary[x]는 values

loop thru dictonary

 

 

 

 

 

댓글 남기기