list - Iterate through lines changing only one character python -


i have file looks this

n1 1.023 2.11 3.789   cl1 3.124 2.4534 1.678  cl2 # # #  cl3 # # #  cl4  cl5  n2  cl6  cl7  cl8  cl9  cl10  n3  cl11   cl12  cl13  cl14  cl15 

the 3 numbers continue down throughout.

what pretty permutation. these 3 data sets, set 1 n1-cl5, 2 n2-cl10, , set 3 n3 - end.

i want every combination of n's , cl's. example first output

cl1  n1  cl2 

then else same. next set cl1, cl2, n1, cl3...and on.

i have code won't want, becuase know there 3 individual data sets. should have 3 data sets in 3 different files , combine, using code like:

list1 = ['cl1','cl2','cl3','cl4', 'cl5']  line in file1:     line.replace('n1', list1(0))     list1.pop(0)     print >> file.txt, line, 

or there better way?? in advance

this should trick:

from itertools import permutations  def print_permutations(in_file):     separators = ['n1', 'n2', 'n3']     cur_separator = none     related_elements = []      open(in_file, 'rb') f:         line in f:             line = line.strip()              # split nx , cix numbers.             value = line.split()[0]              # found new nx. print previous permutations.             if value in separators , related_elements:                 perm in permutations([cur_separator] + related_elements)                     print perm                 cur_separator = line                 related_elements = []             else:                 # found new cix. append list.                 related_elements.append(value) 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -