Python Forum
number of items per line
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
number of items per line
#1
Quote: I've created a list of numbers. I need to print 10 numbers per line, so they're all lined up one underneath the other. I'm having trouble trying to figure out how to remove the brackets [] and know how to print them lined up. Any advice welcome. Thanks!

def odd() :
    new_list = []
    for i in range(1,50,2) :
        if i % 2 != 0 :
            new_list.append(i)    
    for i in range(0, len(new_list), 10):
        print(new_list[i:i + 10])
    
odd()
Quote:my output
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
[21, 23, 25, 27, 29, 31, 33, 35, 37, 39]
[41, 43, 45, 47, 49]
:


Quote:EDITED: I've just realized I've gone about this all wrong. My final output should not include commas or brackets. I honestly have no idea how to fix this. Wall

Instead I should have:
1 3 5 7 9 11 13 15 17 19
21 23 25 27 29 31 33 35 37 39

With the values aligning on the right (can't get it to display properly here).
Reply


Messages In This Thread
number of items per line - by kiki1113 - Nov-19-2017, 03:48 AM
RE: number of items per line - by wavic - Nov-19-2017, 08:54 AM
RE: number of items per line - by kiki1113 - Nov-19-2017, 04:33 PM
RE: number of items per line - by nilamo - Nov-19-2017, 04:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Finding Row Number for Items in 2D array fafzal 2 2,453 Jan-10-2019, 06:11 AM
Last Post: fafzal

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020