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 142873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:00:21+00:00 2026-05-11T08:00:21+00:00

In this loop, I’m trying to take user input and continually put it in

  • 0

In this loop, I’m trying to take user input and continually put it in a list till they write ‘stop’. When the loop is broken, the for loop prints out all of the li’s.

How would I take the output of the for loop and make it a string so that I can load it into a variable?

x = ([]) while True:     item = raw_input('Enter List Text (e.g. <li><a href='#'>LIST TEXT</a></li>) (Enter 'stop' to end loop):\n')     if item == 'stop':         print 'Loop Stopped.'         break                else:         item = make_link(item)         x.append(item)         print 'List Item Added\n'       for i in range(len(x)):         print '<li>' + x[i] + '</li>\n' 

I want it to end up like this:

Code:

print list_output 

Output:

<li>Blah</li> <li>Blah</li> <li>etc.</li> 
  • 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. 2026-05-11T08:00:21+00:00Added an answer on May 11, 2026 at 8:00 am

    In python, strings support a join method (conceptually the opposite of split) that allows you to join elements of a list (technically, of an iterable) together using the string. One very common use case is ', '.join(<list>) to copy the elements of the list into a comma separated string.

    In your case, you probably want something like this:

    list_output = ''.join('<li>' + item + '</li>\n' for item in x) 

    If you want the elements of the list separated by newlines, but no newline at the end of the string, you can do this:

    list_output = '\n'.join('<li>' + item + '</li>' for item in x) 

    If you want to get really crazy, this might be the most efficient (although I don’t recommend it):

    list_output = '<li>' + '</li>\n<li>'.join(item for item in x) + '</li>\n' 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to clean up this type of loop using LINQ? List<Car>
I am trying to loop through a bunch of documents I have to put
I want to write this bash loop for zsh while true; do echo print
When reviewing, I sometimes encounter this kind of loop: i = begin while (
I know that in JavaScript, creating a for loop like this: for(int i =
I've made this decorator, which results in an infinite redirect loop. The problem is
This is my first post here and I wanted to get some input from
This loop checks if a record is in the sqlite database and builds a
This loop works fine but prematurely quits at times. I set a piece of
This loop takes forever to run as the amount of items in the loop

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.