Home>

#pythonVersion One line of content output by line

a="aa1 one bb2 two cc3 three dd4 four ee5 five ff6 six gg7 seven hh8 eight ii9 nine"
"" "
The branch output is:
abcdefghi
abcdefghi
123456789
one two three four five six seven eight nine
"" "
print ("Method one:================")
for r in range (0,4):
 t=""
 for s in range (0 + r, len (a), 4):
  t=t + a [s]
 print (t)
print ("Method two:================)
#=_=Will this method look stupid?
l=list (a)
ta=tb=tc=td=""
for r in range (0,9):
 for s in range (0,4):
  if s == 0:
   ta=ta + l.pop (0)
  if s == 1:
   tb=tb + l.pop (0)
  if s == 2:
   tc=tc+ l.pop (0)
  if s == 3:
   td=td + l.pop (0)
print (ta)
print (tb)
print (tc)
print (td)
print ("Method 3:There are n ways to write back characters ===============")
import string
ta=tb=tc=td=""
la=string.ascii_lowercase
ua=string.ascii_uppercase
nb=string.digits
ub="One Two Three Four Five Six Seven Eight Nine"
for s in a:
 if s in la:
  ta=ta + s
 if s in ua:
  tb=tb + s
 if s in nb:
  tc=tc+ s
 if s in ub:
  td=td + s
print (ta)
print (tb)
print (tc)
print (td)
print ("Method 4:Echoes have a way of writing regular expressions =============== '')
import re
#This regular writing feels unscientific,No good ideas for now
reg=["[a-z]", "[a-z]", "\ d", "[^ \ da-za-z]"]
for s in reg:
 rega=re.compile (s)
 s=re.findall (rega, a)
 print ("". join (s))
"" "
Output:
Method 1:================
abcdefghi
abcdefghi
123456789
one two three four five six seven eight nine
Method 2:================
abcdefghi
abcdefghi
123456789
one two three four five six seven eight nine
Method 3:There are n ways to write back words ================
abcdefghi
abcdefghi
123456789
one two three four five six seven eight nine
Method 4:There is a wording called regex ===============
abcdefghi
abcdefghi
123456789
one two three four five six seven eight nine
"" "

Give you a method to read the content of the file and output it in separate lines.

f=open ("shuju.txt", "r")
content=f.read ()
print content
for i in content:
  print i
f.close ()
f=open ("shuju.txt", "w")
f.write (content)
f.close ()

Well, the little friends study it yourself.Interesting.

  • Previous Android programming method to achieve 3D sliding rotation effect
  • Next JS layer effect code for scrolling with a scroll bar on a web page