def add_one(n):
return n + 1
result2 = list(map(add_one, myList)) # map반환을 list 로 변환
print(f'result2 : {result2}')
출처: https://blockdmask.tistory.com/531 [개발자 지망생:티스토리]
map(function, iterable)
=> map(적용시킬 함수, 적용할 값들)
map함수 안 function의 동작은 두 번째 인자로 들어온 반복 가능한 자료형(리스트나 튜플)을 첫 번째 인자로 들어온 함수에 하나씩 집어넣어서 수행하는 함수
예시
# map 함수 이용
def add_one(n):
return n + 1
# map 함수를 list화
result2 = list(map(add_one, myList))
print(f'result2 : {result2}')
def reaminder(A,B,C):
print((A+B)%C)
print(((A%C) + (B%C))%C)
print((A*B)%C)
print(((A%C) * (B%C))%C)
A,B,C = map(int,input().split(" "))
reaminder(A,B,C)
def reaminder(A,B,C):
print((A+B)%C)
print(((A%C) + (B%C))%C)
print((A*B)%C)
print(((A%C) * (B%C))%C)
A,B,C = int(input().split(" "))
reaminder(A,B,C)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
이 오류 이후 map 함수 찾아서 적용함
메모리 | 시간 | 코드 길이 |
---|---|---|
30840 | 68 | 171 |