
[24.06.23] 99클럽 코테 스터디 35일차 TIL - 이중 리스트 flatten
·
회고
itertools.chain()표준 라이브러리인 itertools의 chain()이라는 함수는 여러개의 iterable을 하나의 iterable로 합쳐준다.즉 인자로 받은 iterable을 순차적으로 연결하여 만든 하나의 새로운 iterable을 반환하는 함수이다.def chain(*iterables): # chain('ABC', 'DEF') → A B C D E F for iterable in iterables: yield from iterable 하지만 단순히 chain에 중첩 리스트를 넣는다고 flatten되는 것은 아니다. nested_list가 하나의 iterable로 처리되기 때문이다. 즉 nested_list 안에 있는 각 리스트가 하나의 원소로 취급되어 flatten..