I have a list like this
a = ['h','a','i']
and I am printing the values of list in a file.
fo = open('file.txt','w')
for i in a:
fo.write(i)
fo.close()
but i want the output like this,
1. h
2. a
3. i
which means I need to print the values with number bullet. How can I achieve this one.
I have tried with this code
count = 0
fo = open('file.txt','w')
for i in a:
count+=1
fo.write("%s. %s"%(count,i))
fo.close()
But if the string length in the list is high, the result is not coming with proper alignment.
I am getting output like
But i need the output like this
For example, if I have a string like this,
a = '<help>somthing data</help><help-error> something data </help-error><help-msg>some data</help-msg><help-info>some data</help-info>'
and I am trying with this code
fo=open('file.txt','w')
count = 0
if '<help-error>' in a:
count+=1
msg = re.search(r'<help-msg>(.*)</help-msg>',a).group()
info = re.search(r'<help-info>(.*)</help-info>',a).group()
fo.write("%s. %s\n"%(count,msg))
fo.write("%s\n"%(info))
How can I achieve the same number bullet concept here.