파이썬 Randomizing a list in Python
파이썬에서 항목 목록을 "흔드는"좋은 방법이 있는지 궁금합니다. 예를 들어 [1,2,3,4,5] 는 [3,1,4,2,5] (모든 순서가 동일하게 ). 해결 방법 from random import shuffle list1 = [1,2,3,4,5] shuffle(list1) print list1 ---> [3, 1, 2, 4, 5] 참조 페이지 https://stackoverflow.com/questions/34862378
2020. 11. 11.
파이썬 Python 카운터 키 () 반환 값
이미 발생 횟수로 정렬 된 카운터가 있습니다. counterlist = Counter({'they': 203, 'would': 138, 'your': 134,...}). 하지만 counterlist.keys () 를 수행하면 반환 목록은 다음과 같습니다. ['wirespe', 'four', 'accus',...] 대신에 ['they', 'would', 'your',...]. 왜? 해결 방법 카운터 () Counter는 해시 가능한 객체를 계산하기위한 dict 하위 클래스입니다. 요소가 사전 키로 저장되고 개수가 사전 값으로 저장되는 정렬되지 않은 컬렉션입니다. from collections import * class OrderedCounter(Counter, OrderedDict): pass counte..
2020. 11. 10.