I want to create a program in python or Matlab to divide a sequence into pairs such that first letter pairs with all other letters and give the values to these pairs. Example "ABCBADD" AB=1 AC=1/2 AB=1/3 AA=1/4 AD=1/5 AD=1/6 Now skip first letter of sequence "BCBADD" BC=1 BB=1/2 BA=1/3 BD=1/4 BD=1/5 Now skip first and so on "CBADD" and add same pair values as AB=1 1/3,AD=1/5 1/6,BD=1/4 1/5 I will be thankful to help me
CodePudding user response:
you could do with two loop:
s = "ABCBADD"
output = [(s[i] c, 1 /(idx 1)) for i in range(len(s) -1) for idx, c in enumerate(s[i 1:])]
output:
print(output)
[('AB', 1.0),
('AC', 0.5),
('AB', 0.3333333333333333),
('AA', 0.25),
('AD', 0.2),
('AD', 0.16666666666666666),
('BC', 1.0),
('BB', 0.5),
('BA', 0.3333333333333333),
('BD', 0.25),
('BD', 0.2),
('CB', 1.0),
('CA', 0.5),
('CD', 0.3333333333333333),
('CD', 0.25),
('BA', 1.0),
('BD', 0.5),
('BD', 0.3333333333333333),
('AD', 1.0),
('AD', 0.5),
('DD', 1.0)]