python - Use list items as values in list comprehension -


i have list in such format:

com = ['eto', 'eti', 'etn', 'ets', 'eot', 'eoi', 'eon', 'eos', 'eit', 'eio', 'ein'] 

then in program need perform 3 different calculations each character in each cell.

newc = [w.replace(mcommon[0], com[e]) w in newc] newc = [w.replace(mcommon[0], com[t]) w in newc] newc = [w.replace(mcommon[0], com[o]) w in newc] 

and next time

newc = [w.replace(mcommon[0], com[e]) w in newc] newc = [w.replace(mcommon[0], com[t]) w in newc] newc = [w.replace(mcommon[0], com[i]) w in newc] 

and on, in loop, don't hardcode characters, should takes list.

essentially want 3 list comprehensions cycle through each combination example first time use 'e', 't' , 'o' respectively, 'e', 't', , 'i' respectively , on.

what index out of range obvious reasons. , m part incorrect, cause not change.

if want function does:

newc = [w.replace(mcommon[0], 'e') w in newc] newc = [w.replace(mcommon[0], 't') w in newc] newc = [w.replace(mcommon[0], 'o') w in newc] 

in first call and:

newc = [w.replace(mcommon[0], 'e') w in newc] newc = [w.replace(mcommon[0], 't') w in newc] newc = [w.replace(mcommon[0], 'i') w in newc] 

in second call write:

com = ['eto', 'eti', 'etn', 'ets', 'eot', 'eoi', 'eon', 'eos', 'eit', 'eio', 'ein'] g_com_index = 0  def adapt_c(newc):     global g_com_index     c in com[g_com_index % len(com)]         newc = [w.replace(mcommon[0], c) w in newc]     g_com_index += 1      return newc 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -