Example of how to find in a list the elements starting by *** in python:
Lets create a liste with words:
l = ['name', 'address_01', 'address_02', 'address_03', 'job', 'income']
For example, lets select only the words that start by 'address' using a list comprehension and the python method startswith():
sub_l = [i for i in l if i.startswith('address')]
['address_01', 'address_02', 'address_03']
To find the indexes, a solution is to use index():
indexes = [l.index(i) for i in sub_l]
[1, 2, 3]
Hi, I am Ben.
I have developed this web site from scratch with Django to share with everyone my notes. If you have any ideas or suggestions to improve the site, let me know ! (you can contact me using the form in the welcome page). Thanks!