"리스트 슬라이싱"의 두 판 사이의 차이

(새 문서: ==개요== ;리스트 슬라이싱 ==Python== {{참고|Python 리스트 슬라이싱}} <syntaxhighlight lang='python' run> numbers = [100,200,300,400,500,600,700] print( numbers[0:3]...)
 
 
(같은 사용자의 중간 판 3개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
==개요==
;리스트 슬라이싱
;리스트 슬라이싱
[[분류: 리스트]]
[[분류: 슬라이싱]]
==C++==
{{참고|C++ 벡터 슬라이싱}}
<syntaxhighlight lang='cpp' run>
#include <iostream>
#include <vector>
using namespace std;
int main() {
    vector<int> v = {100,200,300,400,500,600,700};
    vector<int> v2;
    v2 = vector<int>(v.begin()+0, v.begin()+3);
    for(auto el: v2) cout << el << ' '; cout << '\n'; // 100 200 300
    v2 = vector<int>(v.begin(), v.begin()+5);
    for(auto el: v2) cout << el << ' '; cout << '\n'; // 100 200 300 400 500
    v2 = vector<int>(v.begin()+3, v.end());
    for(auto el: v2) cout << el << ' '; cout << '\n'; // 400 500 600 700
}
</syntaxhighlight>


==Python==
==Python==

2023년 12월 24일 (일) 10:57 기준 최신판

1 개요[ | ]

리스트 슬라이싱

2 C++[ | ]

#include <iostream>
#include <vector>
using namespace std;

int main() {
    vector<int> v = {100,200,300,400,500,600,700};
    vector<int> v2;
    v2 = vector<int>(v.begin()+0, v.begin()+3);
    for(auto el: v2) cout << el << ' '; cout << '\n'; // 100 200 300 
    v2 = vector<int>(v.begin(), v.begin()+5);
    for(auto el: v2) cout << el << ' '; cout << '\n'; // 100 200 300 400 500 
    v2 = vector<int>(v.begin()+3, v.end());
    for(auto el: v2) cout << el << ' '; cout << '\n'; // 400 500 600 700 
}

3 Python[ | ]

numbers = [100,200,300,400,500,600,700]
print( numbers[0:3] ) # [100, 200, 300]
print( numbers[:5] )  # [100, 200, 300, 400, 500]
print( numbers[3:] )  # [400, 500, 600, 700]
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}