코딩테스트/Python 개념

[Python] 한 줄에 여러값 입력받기 map(int,input().split())

박소민 2023. 2. 8. 22:47
한 줄에 여러값 입력받기

 

ls.append( ~~~) 안에

  • list(map(int,input().split())) 
  • set(map(int,input().split())) → pop 했을때 순서대로가 아닌 정렬되서 나옴
  • map(int,input().split())

-> 뭘 하던간에 a,b= ls.pop(0)하면 하나씩 값 받아옴

값꺼내서 쓸꺼면 굳이 list 쓸필요 없이 바로 넣어도 된다.

n,m=map(int,input().split())
ls=[]
for i in range(m):
  ls.append(map(int,input().split()))

while ls:
  a,b=ls.pop(0)
  print(a,b)
  
#입력  
4 2
12 3
15 4
#결과
12 3
15 4