Home > other >  About the for x x in confusion
About the for x x in confusion

Time:09-26

Import the random
F=open (' 7.3. TXT ', 'w')
For y in range (10) :
For the x in the range (10) :
Randnums=STR (random randint (0100 0))
if x !=9:
F.w rite (' {} '. The format (randnums + '))
Elif x==y==9:
F.w rite (randnums)
The else:
F.w rite (' {} '. The format (randnums + '\ n'))
F. lose ()

Fr=open (' 7.3. TXT ', 'r'). The read (). The replace (" ", ', ')
Print (fr, '\ n')

Ls=[]
Ls=fr. Split (' \ n ')
Print (ls, '\ n')

# # ls1 [x.s plit (', ') for x in ls]
# # print (ls1)

ls1=[]
For x in ls:
Ls1=x.s plit (', ')
Print (ls1)


Blue code is my personal understanding of the code red, but the results did not conform to,
Code red print (ls1) can output a set of 2 d data,
Code blue print (ls1) output multiple sets of one-dimensional data,
And if the code blue print (ls1) thus writing, only keep the last row,
Thus written with red code print (ls1) results vary wildly,

Refer to teachers: red code part with what way to express it?
Beginners small white, don't understand the profound, please try to use simple code that,

  • Related