I have the following list of dictionaries:
[{'Sequence': 'TGACCCTGCTTGGCGATCCCGGCGTTTC', 'Start': '52037', 'Strand': '+', 'End': '52064'}, {'Sequence': 'TGATCGCGCAACTGCAGCGGGAGTTAC', 'Start': '188334', 'Strand': '+', 'End': '188360'}, {'Sequence': 'TGATCCGGCACTCGTTGGAGTTCGTATC', 'Start': '245882', 'Strand': '+', 'End': '245909'}, {'Sequence': 'TGACCTTGGTCAGATCGATGACCGTAAT', 'Start': '318422', 'Strand': '+', 'End': '318449'}, {'Sequence': 'TGACCCGCGTATTTTGGAGCAGAAGTATC', 'Start': '343421', 'Strand': '+', 'End': '343449'}, {'Sequence': 'TGATCCGGCACTCGTTGGAGTTCGTATC', 'Start': '359576', 'Strand': '+', 'End': '359603'}, {'Sequence': 'TGATCGGCAATTCCTATGGCAAGTATC', 'Start': '457457', 'Strand': '+', 'End': '457483'}, {'Sequence': 'TGATCGAGGCGCCAGTTGTGCCCGTATT', 'Start': '627296', 'Strand': '+', 'End': '627323'}, {'Sequence': 'TGATCCAAGTGAACCCCCGCCCAGTAAA', 'Start': '637265', 'Strand': '+', 'End': '637292'}, {'Sequence': 'TGACCGGAAGACCGCCGTCGAGCGTATC', 'Start': '829035', 'Strand': '+', 'End': '829062'}, {'Sequence': 'TGATCGCGGCACCGACACCGGTCGTAAT', 'Start': '864440', 'Strand': '+', 'End': '864467'}, {'Sequence': 'TGATCGTTTCCGTGCTCGGAGCGTATC', 'Start': '934160', 'Strand': '+', 'End': '934186'}, {'Sequence': 'TGACCTGGCTCGAGGCCTGAGGAGTAAA', 'Start': '1162006', 'Strand': '+', 'End': '1162033'}, {'Sequence': 'TGACCCGCCGCAACATCCCCTTCGTAAA', 'Start': '1294515', 'Strand': '+', 'End': '1294542'}]
I would like to acquire the following output (redirecting prints via sys.stdout):
Start:1234 End:5678 Strand:+ Sequence:ABCDEFG
...
So far, my idea involves looping through the list and using the get-method to get the value of the key and then do a manual printout, basically like this:
for item in dictList:
print("Start"+item.get('Start'))
print("End"+item.get('End'))
...
I am not sure how to deal with the newlines though. I read about sys.stdout flush to avoid newlines, but since I do not want to avoid all newlines, I am not sure if this would suit my aim.
Is there a smarter/shorter way to do this?
Update
Thanks to Aleksey, I thought of changing my print statement to:
for item in dictList:
print("Start"+str(item.get('Start'))+" "+"End"+str(item.get('End'))+" "+"Strand"+str(item.get('Strand'))+" "+"Sequence: "+str(item.get('Sequence')))
Update2
so far, I am sticking to this:
print(ecf+" "+replicon+" - "+"Validated results: Total number of hits: "+str(len(finalList)))
print("")
for item in finalList:
print("Start: "+str(item.get('Start'))+" "+"End: "+str(item.get('End'))+" "+"Strand: "+str(item.get('Strand'))+" "+"Sequence: "+str(item.get('Sequence')))
which prints:
ECF02 pSymA - Validated results: Total number of hits: 284
Start: 2876 End: 2903 Strand: + Sequence: GAACTACAGGAAGTTCATGGTCTCCTTC
Start: 2876 End: 2900 Strand: + Sequence: GAACTACAGGAAGTTCATGGTCTCC
Start: 9214 End: 9238 Strand: + Sequence: GAACGTCGGGCGCAAGAGCCGCTTT
...
please note: dictList was replaced by finalList. Due to parts of my script running before those prints