简体   繁体   中英

How to remove the brackets from the list within the list?

p = [[10,10,10],[11,11,11]]
for i in range(0,2):
    print("progress = ",p[i])

When I print this i get -

progress =  [10, 10, 10]
progress =  [11, 11, 11]

I want to remove the brackets from the above list

The i values in the for loop are inner lists. To remove the brackets, unpack the list using *. Your code:

p = [[10,10,10],[11,11,11]]
for i in range(0,2):
    print("progress = ",*p[i])

You can do this to remove the brackets from the list:

  p = [[10,10,10],[11,11,11]]
  for i in range(0,2):
    print(str(p[i])[1:-1])

Replace p[i] with

(", ".join([str(x) for x in p[i]]))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM