-1

I have a python string array. How do I index the stop and end of this array with string? i.e. Is there a way I can get from "dad" to "dog", inclusive, by setting the start and stop of this array? I can assume that there are no repetitions, and the unique array is ordered as I want to.

fam_arr = ['mom', 'dad', 'sister', 'brother', 'dog', 'cat']

output: subset_arr = ['dad', 'sister', 'brother', 'dog']

JadeHippo
  • 39
  • 1
  • 1
  • 7

1 Answers1

1

In this case use can use slice for example

fam_arr = ['mom', 'dad', 'sister', 'brother', 'dog', 'cat']
print(fam_arr[1:5])

the result

['dad', 'sister', 'brother', 'dog']

but if you don't know where is the index of dad and dog you need to search the index of the list after that you can use slice