I am trying to have a basic function to find a string inside another string in a nested list. But its unable to find the same. Is anything fundamentally wrong ?
import Tkinter, Tkconstants, tkFileDialog
from Tkinter import *
import subprocess
import ttk
import re
def find_index_sub_string(needle,haystack):
return [i for i, x in enumerate(haystack) if needle in x]
mc_pool = [['fruit,apple', '1,appl_c', [''], '1,am', '1,as', ['fruit,apple,am-fruit,apple,as-rocky,1'], '/abc/bb/ccc/dd/e', ['1,aa', ['fruit,apple,aa', 'aa', 1, [], [], [], [], [], []]]], ['apple,appl_c', '', [''], '1,mm', '1,ms', ['apple,appl_c,mm-apple,appl_c,ms-rambo,1'], '/aa/bbbd/cc/dddd', ['']]]
mc_pool_cln = [['fruit,apple', '1,appl', ['fruit,apple,mas', 'mas', '5'], '1,am', '1,as', ['fruit,apple,am-fruit,apple,as-rocky,1'], '/abc/bb/ccc/dd/e', ['1,aa', ['fruit,apple,aa', 'aa', 1, [], [], [], [], [], []]]], ['apple,appl', '', [''], '1,mm', '1,ms', ['apple,appl,mm-apple,appl,ms-rambo,1'], '/aa/bbbd/cc/dddd', ['']]]
mc_idx = find_index_sub_string('_c', mc_pool)
print mc_idx
mc_idx = find_index_sub_string('_c', mc_pool_cln)
print mc_idx
Update:
- Have added another array mc_pool_cn which doesn't contain any of the strings i.e.
_c.. - Was expecting the output like,
[[0,1], [1,0], [1,5]]..i.e. like the respective index location of the sub string that appears..