Find index position of characters in string
<p>I am trawling through a storage area and the paths look a lot like this: 
storagearea/storage1/ABC/ABCDEF1/raw/2013/05/ABCFGM1 </p>

<p>I wont always know what year is it. I need to find the starting index position of the year </p>

<p>Therefor I am looking for where I find the following in the file name (2010, 2011, 2012, 2013, 2014 etc...) </p>

<p>I have set up a list as follows:</p>

<pre><code>list_ = ['2010', '2011','2012','2013','2014', '2015', '2016']
</code></pre>

<p>and I can find if it is in the file name</p>

<pre><code>if any(word in file for word in list_): 
    print 'Yahooo'
</code></pre>

<p>But how do I find the character index of the year in the absolute path? </p>

<p>Instead of using a generator expression (which has its own scope), use a traditional loop and then print the found word's index and <code>break</code> when you find a match:</p>

<pre><code>list_ = ['2010', '2011','2012','2013','2014', '2015', '2016']
for word in list_:
    if word in file:
        print file.index(word)
        break
</code></pre>

python