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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:04:55+00:00 2026-06-15T10:04:55+00:00

Without using reversed(), how would I loop a set of strings in Python in

  • 0

Without using reversed(), how would I loop a set of strings in Python in a function?

Stumbled upon ranges like:

range() and xrange() take a third parameter that specifies a step. So
you can do the following.

range(10, 0, -1) Which gives

[10, 9, 8, 7, 6, 5, 4, 3, 2, 1] But for iteration, you should really
be using xrange instead. So,

xrange(10, 0, -1)

But these don’t really speak to strings?

  • 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-06-15T10:04:57+00:00Added an answer on June 15, 2026 at 10:04 am

    The function you’re looking for is list comprehensions. These are useful in that you don’t have to iterate over a sequence, which is what range and xrange (in 2.x) provide.

    str can be iterated over and sliced, much like strings. The only difference is that str elements are immutable.

    To your example, say you have a set of strings and you want to iterate over them. No problem – just remember that sets have no inherent ordering to them; they only guarantee that the contents are unique.

    myset = set(["first", "second", "third", "fourth", "fifth"])
    for i in myset:
        print i
    

    …which prints:

    second
    fifth
    fourth
    third
    first
    

    It’s also the case that you can reverse a single string by itself using the step parameter for a sequence type, of which str belongs. You can do that with this:

    "this is the song that never ends"[::-1]
    

    …which prints:

    'sdne reven taht gnos eht si siht'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible without using exponentiation to have a set of numbers that when
I want to write string reverse function without using either append or reverse functions.
Given a list, I'd like to divide it into clusters using a boundary function.
Without using any other jquery plugin I'm looking to continuously flash/change a div's border
Without using jQuery, what is the best way to limit text entry of a
without using a database i wanted a file to point to the newest revision
Without using percentages, is it possible to position a background image 2px from the
Without using iframes, is it possible to load the contents of <div id=siteloader></div> With
Without using the Graphic Resources how can I create and build up a CTabCtrl?
I wrote code first without using functions to prototype, and of course, it worked

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.