I have a list = ['0.2 0.2 0.3 0.2 0.3', '0.4 0.3 0.1 0.5 0.1', '0.3 0.3 0.5 0.2 0.4', '0.1 0.2 0.1 0.1 0.2'] and I need to put a comma to separate the elements like that: '0.2, 0.2, 0.3, 0.2, 0.3'... I am parsing a file and I got stuck in this step.
I have tried this:
with open('profileKmer.txt') as f:
lines = f.read().splitlines()
prof = [x.strip(' ') for x in lines[4:8]]
profile = []
for element in prof:
if element.startswith('0'):
profile.extend(element.split(','))
print(profile)
But I didn't get what I wanted.
The data looks like that:
headline
input
ACCTGTTTATTGCCTAAGTTCCGAACAAACCCAATATAGCCCGAGGGCCT
5
0.2 0.2 0.3 0.2 0.3
0.4 0.3 0.1 0.5 0.1
0.3 0.3 0.5 0.2 0.4
0.1 0.2 0.1 0.1 0.2
I really appreciate any insight.
splitwith a' 'argument to split on single spaces into a list. It's not really clear whether you want your output to be a python list or a string with commas separating the numbers - Andrewfoo.split()and then",".join(foo). This is assuming that you want a comma separated set of strings, otherwise you are done after thefoo.split(), potentially with alist.extendif you want them all in one list. - Bas Jansen