순열 일치: 긴 목록과 짧은 목록 정렬
길이가 서로 다른 두 목록이 주어지면 길이에 따라 쌍을 만드는 것을 목표로 합니다. 짧은 목록. 더 짧은 목록의 각 요소는 더 긴 목록의 요소 순열에 해당해야 합니다.
예를 들어 이름 = ['a', 'b'] 및 숫자 = [1, 2]인 경우
[('a', 1), ('b', 2)] [('b', 1), ('a', 2)]
이름 = ['a', 'b', 'c']와 같이 이름 목록이 더 긴 경우 순열은 다음을 포함하도록 확장됩니다.
[('a', 1), ('b', 2)] [('b', 1), ('a', 2)] [('a', 1), ('c', 2)] [('c', 1), ('a', 2)] [('b', 1), ('c', 2)] [('c', 1), ('b', 2)]
itertools.product를 사용한 솔루션
간단한 접근 방식은 Python 표준 라이브러리의 itertools.product 함수를 활용하는 것입니다. 입력 반복 가능 항목의 데카르트 곱을 생성하여 가능한 모든 조합을 생성합니다.
import itertools a = ["foo", "melon"] b = [True, False] c = list(itertools.product(a, b)) # Output: # [("foo", True), ("foo", False), ("melon", True), ("melon", False)]
특정 사례에서는 itertools.product를 사용하여 더 짧은 목록의 요소를 긴 목록의 순열과 쌍을 이룰 수 있습니다. 순열은 긴 목록 요소의 가능한 모든 재정렬을 나열하여 생성됩니다.
위 내용은 순열을 사용하여 짧은 목록과 긴 목록의 요소를 쌍으로 연결하는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

Pythonusesahybridmodelofilationandlostretation : 1) ThePyThoninterPretreCeterCompileSsourcodeIntOplatform-IndependentBecode.

Pythonisbothingretedandcompiled.1) 1) it 'scompiledtobytecodeforportabilityacrossplatforms.2) thebytecodeisthentenningreted, withfordiNamictyTeNgreted, WhithItmayBowerShiledlanguges.

forloopsareusedwhendumberofitessiskNowninadvance, whilewhiloopsareusedwhentheationsdepernationsorarrays.2) whiloopsureatableforscenarioScontiLaspecOndCond

pythonisnotpurelynlogreted; itusesahybrideprophorfbyodecodecompilationandruntime -INGRETATION.1) pythoncompilessourcecodeintobytecode, thepythonVirtualMachine (pvm)

ToconcatenatelistsinpythonwithesameElements, 사용 : 1) OperatorTokeEpduplicates, 2) asettoremovedUplicates, or3) listComperensionForControlOverDuplicates, 각 methodHasDifferentPerferformanCeanDorderImpestications.

PythonisancerpretedLanguage, 비판적 요소를 제시하는 PytherfaceLockelimitationsIncriticalApplications.1) 해석 된 언어와 같은 thePeedBackandbackandrapidProtoTyping.2) CompilledlanguagesLikec/C transformt 해석

useforloopswhhenmerfiterationsiskNownInAdvance 및 WhileLoopSweHeniTesslationsDepoyConditionismet whilEroopsSuitsCenarioswhereTheLoopScenarioswhereTheLoopScenarioswhereTheLoopScenarioswhereTherInatismet, 유용한 광고 인 푸트 gorit


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

맨티스BT
Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.