I work with python and I have a really basic question.
I an array of 1000 elements. I want to select 100 positions of this array.
I want to do something like
selected_value=array[i for i in position_to_select]
How can I make this work?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Suppose you have the list
arr, from which you want to select elements at positions 0, 4, 2:I think that the key difference with your original code sample is using
arr[i]in the list comprehension. A list comprehension creates a new list. It is not used to index an existing list.