extend() 대 추가() 대 insert():
extend()-iterable(예: 목록, 튜플)의 모든 요소를 목록 끝에 추가합니다.
append()-목록 끝에 단일 요소를 추가합니다.
insert()-목록의 지정된 인덱스에 단일 요소를 삽입합니다.
extend()의 예:
l1 = [10,20,30] l2 = [40,50,60] l1.extend(l2) print(l1) print(len(l1))
[10, 20, 30, 40, 50, 60] 6
append()의 예:
l1 = [10,20,30] l2 = [40,50,60] l1.append(l2) print(l1) print(len(l1))
[10, 20, 30, [40, 50, 60]] 4
추가() 대 확장():
l1 = [10,20,30] l1.append('abcd') print(l1) l1.extend('pqrs') print(l1)
[10, 20, 30, 'abcd'] [10, 20, 30, 'abcd', 'p', 'q', 'r', 's']
역방향():
Python의 reverse() 메서드는 목록에 있는 요소의 순서를 반대로 바꾸는 데 사용됩니다.
l1 = [10,20,30] l1.reverse() print(l1)
[30, 20, 10]
정렬():
Python의 sort() 메서드는 목록의 요소를 제자리에 정렬하는 데 사용됩니다. 기본적으로 요소를 오름차순으로 정렬합니다.
l1 = [10,200,30] l1.sort() print(l1) l1.sort(reverse=True) print(l1)
[10, 30, 200] [200, 30, 10]
정렬():
Python의 sorted() 함수는 sort() 메서드와 유사하지만 중요한 차이점이 있습니다. 원래 목록을 수정하지 않고 새로 정렬된 목록을 반환합니다.
my_list = [3, 1, 4, 5, 2] sorted_list = sorted(my_list) print(sorted_list) print(my_list)
[1, 2, 3, 4, 5] [3, 1, 4, 5, 2]
min(): 주어진 입력에서 최소값을 찾습니다.
max(): 주어진 입력에서 최대값을 찾습니다.
sum(): 주어진 입력에 포함된 모든 값의 합계를 구합니다.
l1 = [10,200,30,40,50] print(min(l1)) print(max(l1)) print(sum(l1))
10 200 330
inf(인피니티):
float('inf'):최대 수를 찾는 데 사용됩니다.
-float('inf'):최소 수를 찾는 데 사용됩니다.
1. 주어진 입력에서 두 번째 최소값을 찾습니다.
l1 = [10,20,310,40,50] min_value = float('inf') second_min = float('inf') i = 0 while i <len if l1 second_min="min_value" min_value="l1[i]" elif i else: print> <pre class="brush:php;toolbar:false">20
2. 주어진 입력에서 두 번째 최대값을 찾습니다.
l1 = [10,20,30,40,50] max_value = -float('inf') second_max = -float('inf') i = 0 while i <len if l1>max_value: second_max = max_value max_value = l1[i] elif l1[i]>second_max: second_max = l1[i] i+=1 else: print(second_max) </len>
40
버블 정렬:
인접한 요소를 비교하여 순서가 잘못된 경우 교체합니다.
예:1
l1 = [40,30,20,10] i = 0 while i<len if l1>l1[i+1]: l1[i], l1[i+1] = l1[i+1], l1[i] i+=1 print(l1) i = 0 while i<len if l1>l1[i+1]: l1[i], l1[i+1] = l1[i+1], l1[i] i+=1 print(l1) </len></len>
[30, 20, 10, 40] [20, 10, 30, 40]
예:2(주어진 목록을 오름차순으로 이중 정렬 변경하고 주어진 목록에서 K번째로 높은 값 찾기)
l1 = [40,30,20,10] #kth highest value in a given list j = 1 while jl1[i+1]: l1[i], l1[i+1] = l1[i+1], l1[i] i+=1 j+=1 print(l1) print(l1[-3])
[10, 20, 30, 40] 20
연산자 안과 안:
Python의 in 및 not in 연산자를 사용하면 주어진 값이 값 모음의 일부인지 아닌지 빠르게 확인할 수 있습니다.
l1 = [100,67,54,101,220, 670,45, 32] print(100 in l1) print(100 not in l1) print(120 in l1) print(120 not in l1)
True False False True
문자열 반전:
s = "today is thursday" reverse = "" i = 0 while i<len reverse="reverse" s i print> <pre class="brush:php;toolbar:false">yadsruht si yadot
위 내용은 일 - 목록 기능의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

forhandlinglargedatasetsinpython, usenumpyarraysforbetterperformance.1) numpyarraysarememory-effic andfasterfornumericaloperations.2) leveragevectorization foredtimecomplexity.4) managemoryusage withorfications data

inpython, listsusedyammoryAllocation과 함께 할당하고, whilempyarraysallocatefixedMemory.1) listsAllocatemememorythanneedInitiality.

Inpython, youcansspecthedatatypeyfelemeremodelerernspant.1) usenpynernrump.1) usenpynerp.dloatp.ploatm64, 포모 선례 전분자.

numpyissentialfornumericalcomputinginpythonduetoitsspeed, memory-efficiency 및 comperniveMathematicaticaltions

contiguousUousUousUlorAllocationScrucialForraysbecauseItAllowsOfficationAndFastElementAccess.1) ItenableSconstantTimeAccess, o (1), DuetodirectAddressCalculation.2) Itimprovesceeffiency theMultipleementFetchespercacheline.3) Itsimplififiesmomorym

slicepaythonlistisdoneusingthesyntaxlist [start : step : step] .here'showitworks : 1) startistheindexofthefirstelementtoinclude.2) stopistheindexofthefirstelemement.3) stepisincrementbetwetweentractionsoftortionsoflists

NumpyAllowsForVariousOperationsOnArrays : 1) BasicArithmeticLikeadDition, Subtraction, A 및 Division; 2) AdvancedOperationsSuchasmatrixmultiplication; 3) extrayintondsfordatamanipulation; 5) Ag

Arraysinpython, 특히 Stroughnumpyandpandas, areestentialfordataanalysis, setingspeedandefficiency


핫 AI 도구

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

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

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

Clothoff.io
AI 옷 제거제

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

인기 기사

뜨거운 도구

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기

Dreamweaver Mac版
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)
