리스트 슬라이싱

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 }}