Hello guys,
just joined the community. Found it through google. :)
I am basically new to python, only couple of days of knowledge. I am trying to
make all the words in a txt file appear in 4 or 5 in a row.
so the txt file looks like this:
!algiers!
!atlanta!
!baghdad!
!bangkok!
!beijing!
!bogota!
!buenos aires!
!cairo!
!chennai!
!chicago!
!delhi!
!essen!
!ho chi mihn ci
!hong kong!
!istanbul!
!jakarta!
!johannesburg!
and the out put should be:
!algiers! !atlanta! !baghdad! !bangkok!
!beijing! !bogota! !buenos aires! !cairo!
This is the code I used so far
f = file('cities.txt','r')
while True:
line = f.readline()
if len(line) == 0:
break
x= line.strip()
x= '!'+x+'!'
x= x[0:15]
x= x.rjust(15)
print x
I used .split but not getting the same result. I dont know what to do now.