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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:40:20+00:00 2026-06-14T12:40:20+00:00

In advance, I have searched for a solution to this problem already but there

  • 0

In advance, I have searched for a solution to this problem already but there does not seem to be one in existence. So I am currently trying to self teach python by running through the Python "Path" on http://singpath.appspot.com and I ran into a problem I do not understand how to solve. I have tried multiple different ways to solve it but keep coming up with different incorrect results. Any hints/help would be spectacular! Thanks in advance!

Question:

Comparing Strings

Create a function that takes an input of two strings
and returns a string that contains all of the characters that appear
in both of the inputs. The result should not have any repeats and
should be listed in sorted order. You might want to use the
variable lowercase from the string module so that you have all the
letters in order.

My Current Code:

def in_both(s1, s2):
    s1 = s1.lower()
    s2 = s2.lower()
    
    l1=list(''.join(s1.split()))
    l2=list(''.join(s2.split()))
    
    same = ''
    
    for i in l1:
        if i in l2:
            
            same = ''.join(i)
    
    return same

Example:

call: in_both('apple','orange') recieved: 'e' expected: 'ae'

As you can see it is only collecting a single similar character. Any suggestions? I’ve tried a couple of different things but I am unsure where to go from here! Please help!

P.s. I got the list idea from a similar question located here: Python Function to return a list of common letters in first and last names

I understand how it works the problem is I have to return a string with all comparisons at the same time. Thanks ‘the wolf’ for the idea for the list(s) of characters.

  • 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-14T12:40:21+00:00Added an answer on June 14, 2026 at 12:40 pm

    You can get unique characters in any string by turning it into a set.
    The you can get the intersection of two sets using intersection.
    And you can sort the result, which returns a list.

    def in_both(s1, s2):
        s1 = s1.lower()
        s2 = s2.lower()
        s1_chars = set(s1)
        s2_chars = set(s2)
        result = sorted(s1_chars.intersection(s2_chars))
        return result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched all around to find a solution to my problem, but i
I searched all over, but could not find a solution. I have a view
I have searched for solution, but nothing similar. My problem is that I want
i have searched the web relentlessly for this and have not found anything -
I have searched the web for days now but I can't seem to find
i have searched a lot but could not find the exact way to do
I have now searched for hours, but haven't found a solution yet. I hope
I have searched StackOverflow for some time now, but have not been successful so
I am using c# .net. Thanks in advance for any help. I have searched
i have very serious problem if any tech expert can help...thank you in advance..

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.