this 숫자 유형을 얻을 수있는 방법이 있습니까? 파이썬. 이 번호 체계는 무엇이라고 불 립니 까?영숫자가있는 순차 시리즈를 작성하는 Python 프로그램.
01,...0A,.......ZZ
this 숫자 유형을 얻을 수있는 방법이 있습니까? 파이썬. 이 번호 체계는 무엇이라고 불 립니 까?영숫자가있는 순차 시리즈를 작성하는 Python 프로그램.
01,...0A,.......ZZ
당신은 목록을 가져올 수 permutations를 사용할 수 있습니다. 예를 들어
는
import string
import itertools
series = [''.join(r) for r in itertools.permutations([str(i) for i in range(10)]+[str(c) for c in string.ascii_uppercase], 2)]
print(series)
print(len(series)) # got 1260 here
은 1296 조합으로해서는 안됩니까? –
아, 네, 그렇다면 시리즈는 AA BB CC DD .. 00 ... 99를 추가해야합니다. 그래서 2 층의 루프를 사용하여 시리즈를 만들 수 있습니다. – CSJ
현재 제안 잘못이다. 예를 들어 교체를 사용한 조합은 AB
과 BA
을 동시에 제공하지 않으며 첫 번째 만 제공합니다. 그리고 permutations
등 AA
, BB
,
이 대신 당신이 itertools.product
을 사용해야 없습니다. 예를 들어
는 :
import string
import itertools
combinations_generator = itertools.product(string.ascii_uppercase + string.digits,
repeat=2)
combinations = list(map(''.join, combinations_generator))
print(len(combinations))
이것은 당신에게 정확히 1,296 조합을 제공 할 것입니다. // 문서 :
combinations_generator
생성 튜플 등 ('A', 'A')
, ('A', 'B')
처럼
는 그리고 map(''.join, combinations_generator)
으로 우리는 등
사용'itertools' [교체와 조합] (HTTPS
'AA'
,'AB'
처럼 함께 참여합니다 .python.org/3.5/library/itertools.html # itertools.combinations_with_replacement) – MrT