Sorry if the question is a little confusing, but basically I have the following data:
useable = ['osc_1_', 'osc_2_', 'osc_3_', 'sample_', 'filter_1_', 'filter_2_', 'filter_fx_', 'lfo_1_', 'lfo_2_', 'lfo_3_', 'lfo_4_', 'lfo_5_', 'lfo_6_', 'lfo_7_', 'lfo_8_', 'random_1_', 'random_2_', 'random_3_', 'random_4_', 'env_1_', 'env_2_', 'env_3_', 'env_4_', 'env_5_', 'env_6_', 'chorus_', 'compressor', 'delay', 'distortion', 'phaser', 'flanger', 'reverb', 'equalizer']
I also have a string value: x = 'filter_fx_formant_x'
I'm using the following function to return 'True' if x
contains a value that can be found in useable
,
if any(useable in x for useable in useable):
ex: 'filter_fx_' is in both a substring of x
and a value in useable
.
Now here's my question: How can I get the index value of the item that can be found in a substring of x
?
Is there a better way other than any()? Am I missing something obvious? Let me know if you can think of anything.
https://stackoverflow.com/questions/66913216/find-the-index-of-a-value-in-a-list-that-is-also-inside-of-a-string-using-the April 02, 2021 at 08:48AM
没有评论:
发表评论