I am learning python for customizing an application which uses Ironpython 2.7.4. My inputs are as follows:
nids = [1,2,3,4,5,6]
enids = [1,2,2,8,3,4,5,5,6,7,7]
s = [44, 33, 68, 76, 43, 43, 53, 55, 69, 45, 31]
t = [50, 40, 30, 10, 10, 60, 50, 80, 90, 10, 30]
I want elements from enids which are in nids. Also I want elements from s and t at the index of elements from enids which are in nids. I came up with following list comprehensions:
enids = [enid for enid in enids if enid in nids]
s = [s[i] for i, enid in enumerate(enids) if enid in nids]
t = [t[i] for i, enid in enumerate(enids) if enid in nids]
Since all the above list comprehension uses same for and if conditions I wonder if there is any way to simplify the code and save computation time.