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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:56:46+00:00 2026-05-30T21:56:46+00:00

I ran into a problem regarding set in Python 2.7. Here’s the appropriate example

  • 0

I ran into a problem regarding set in Python 2.7.

Here’s the appropriate example code block:

letters = set(str(raw_input("Type letters: ")))

As you can see, the point is to write some letters to assign to “letters” for later use. But if I type “aaabbcdd”, the output of “letters” returns

set(['a', 'c', 'b', 'd'])

My question is how to write the code, so that the output will allow duplicates like this:

set(['a','a','a','b','b','c','d','d'])

?

  • 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-30T21:56:47+00:00Added an answer on May 30, 2026 at 9:56 pm

    set doesn’t store duplicates, which is why it’s called a set. You should use an ordinary str or list and sort it if necessary.

    >>> sorted(raw_input("Type letters: "))
    Type letters: foobar
    ['a', 'b', 'f', 'o', 'o', 'r']
    

    An alternative (but overkill for your example) is the multiset container collections.Counter, available from Python 2.7.

    >>> from collections import Counter
    >>> c = Counter(raw_input("Type letters: "))
    >>> c
    Counter({'o': 2, 'a': 1, 'r': 1, 'b': 1, 'f': 1})
    >>> sorted(c.elements())
    ['a', 'b', 'f', 'o', 'o', 'r']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem this week regarding implicit conversions in C# on collections.
After Lion upgrade, I had to reinstall my python packages, and ran into problem
i ran into a curious problem regarding evaluation of expressions: reference operator()(size_type i, size_type
(this is regarding the Ramaze.net framework) I ran into some really strange problems while
I ran into the problem that my primary key sequence is not in sync
Never ran into this problem with jQuery before. I have the following: $(document).ready(function() {
I've ran into a problem while trying to test following IRepository based on NHibernate:
I recently ran into a problem that I thought boost::lambda or boost::phoenix could help
I recently ran into a problem with a COM object that was using a
I just ran into a problem with the version of JAX-WS in JDK 1.6.0

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.