Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6563995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:54:44+00:00 2026-05-25T13:54:44+00:00

quick and hopefully easy question. Let’s say I have a variable that is equal

  • 0

quick and hopefully easy question.

Let’s say I have a variable that is equal to a numerical width value

i.e.: size_x = 50

I want to print the list, wrapping to a width of 50 elements. How do I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:54:45+00:00Added an answer on May 25, 2026 at 1:54 pm

    guess 1: print lines containing only size_x elements of the original list

    for i in range(len(mylist)/size_x):
        print(mylist[i*size_x:(i+1)*size_x])
    

    guess 2: a new list of which the elements are strings of only size_x characters

    newlist = []
    for i in range(len(mylist)/size_x):
        newlist.append(''.join(mylist[i*size_x:(i+1)*size_x]))
    

    printing newlist of ‘guess 2’ all at once to the screen is quicker than first guess:

    print('\n'.join(newlist))

    (also note that prior to python 3, xrange() can be used instead of range(), which generates i-values ‘on the go’ instead of creating a whole list of indices first. Python 3 does this standard with range())

    example

    mylist = list('hello this is supposed to be a long line')
    size_x=5
    for i in range(len(mylist)/size_x):
        print(mylist[i*size_x:(i+1)*size_x])
    
    ['h', 'e', 'l', 'l', 'o']
    [' ', 't', 'h', 'i', 's']
    [' ', 'i', 's', ' ', 's']
    ['u', 'p', 'p', 'o', 's']
    ['e', 'd', ' ', 't', 'o']
    [' ', 'b', 'e', ' ', 'a']
    [' ', 'l', 'o', 'n', 'g']
    [' ', 'l', 'i', 'n', 'e']
    
    newlist = []
    for i in range(len(mylist)/size_x):
        newlist.append(''.join(mylist[i*size_x:(i+1)*size_x]))
    print('\n'.join(newlist))
    
    hello
     this
     is s
    uppos
    ed to
     be a
     long
     line
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a quick and hopefully simple question that I hope someone can help
I have a (hopefully) quick SQL question that is driving me nuts and I
I have a quick question that hopefully someone has worked through before. In the
Quick (and hopefully easy) question: I need to trigger a download of a PDF
Quick question. What do you think, I have a few sites that use a
Just a (hopefully) quick question, I have the following HTML code: <tr> <td><img src=img/icons/file_pdf.png></td>
Okay, hopefully this is quick and easy. I have two separate java projects, 'Library'
Quick and hopefully obvious question. I have a progmatically created button in my iPhone
Quick question, hopefully I am just missing something simple. Ok I have one class
I have a (hopefully) quick question. I've got some stepper boxes. Though really this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.