1

In my list there are strings such as

A_list= ['mass_32_', 'mass_40_', 'mass_28_']

I want to find the index of an element from an array of just the numbers.

For example

masses=[32,28]

I want to find the index of the ints in masses that correspond to the index in A_list.

Any suggestions of a for/while loop?

vkrams
  • 7,267
  • 17
  • 79
  • 129
sgartz
  • 13
  • 2

1 Answers1

2

Try this:

[A_list.index('mass_{}_'.format(m)) for m in masses]
James
  • 32,991
  • 4
  • 47
  • 70