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

  • Home
  • SEARCH
  • 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 6801691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:07:51+00:00 2026-05-26T19:07:51+00:00

Why does itertools.permutations() return a list of characters or digits for each permutation, instead

  • 0

Why does itertools.permutations() return a list of characters or digits for each permutation, instead of just returning a string?

For example:

>>> print([x for x in itertools.permutations('1234')])
>>> [('1', '2', '3', '4'), ('1', '2', '4', '3'), ('1', '3', '2', '4') ... ]

Why doesn’t it return this?

>>> ['1234', '1243', '1324' ... ]
  • 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-26T19:07:52+00:00Added an answer on May 26, 2026 at 7:07 pm

    itertools.permutations() simply works this way. It takes an arbitrary iterable as an argument, and always returns an iterator yielding tuples. It doesn’t (and shouldn’t) special-case strings. To get a list of strings, you can always join the tuples yourself:

    list(map("".join, itertools.permutations('1234')))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't need the laziness of itertools.groupby. I just want to group my list
Does anyone know if there is a way to get a list of controls
Here is an example use case of itertools.groupby() in Python: from itertools import groupby
Does anyone know of a set of power-saving guidelines for ALSA anywhere? For example...
Does using then instead of semicolon or linebreak have only decorative purpose (to make
Considder the following interactive example >>> l=imap(str,xrange(1,4)) >>> list(l) ['1', '2', '3'] >>> list(l)
I have a list of tuples each with two elements: [('1','11'),('2','22'),('3','33'),...n] How would I
Does $this->db->insert_batch(); insert with 1 table connection or does it insert each row separately
I am trying to create a number of restricted permutations of a list of
I noticed that itertools does not (it seems to me) have a function capable

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.