티스토리 뷰

반응형

리스트에 있는 모든 string 을 int 로  변경하기 

 


Python 3. 

 

map() 에서는 map 객체로 반환하기 때문에 마지막에 한번더 list 로 type 변경해줄 필요가 있다. 

 


Python 2. 

 

map 에 원하는 type 과 함께 넣고 변경하면 된다. 

 

자료출처 : 

https://stackoverflow.com/questions/7422453/python-change-type-of-whole-list

 

Python change type of whole list?

I would like to do something like this def foo(x,dtype=long): return magic_function_changing_listtype_to_dtype(x) i.e. a list full of str to a list full of int any easy way to do it for nested

stackoverflow.com

 

끝. 

 

댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함