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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:57:50+00:00 2026-05-31T11:57:50+00:00

Question: DO NOT USE SETS IN YOUR FUNCTION: Uses lists to return a list

  • 0

Question: DO NOT USE SETS IN YOUR FUNCTION: Uses lists to return a list of the common letters in the first and last names (the intersection) Prompt user for first and last name and call the function with the first and last names as arguments and print the returned list.

I can’t figure out why my program is just printing “No matches” even if there are letter matches. Anything helps! Thanks a bunch!

Code so far:

import string

def getCommonLetters(text1, text2):
""" Take two strings and return a list of letters common to
    both strings."""
    text1List = text1.split()
    text2List = text2.split()
    for i in range(0, len(text1List)):
        text1List[i] = getCleanText(text1List[i])
    for i in range(0, len(text2List)):
        text2List[i] = getCleanText(text2List[i])

    outList = []
    for letter in text1List:
        if letter in text2List and letter not in outList:
           outList.append(letter)
    return outList

def getCleanText(text):
"""Return letter in lower case stripped of whitespace and
punctuation characters"""
    text = text.lower()

    badCharacters = string.whitespace + string.punctuation
    for character in badCharacters:
        text = text.replace(character, "")
    return text

userText1  = raw_input("Enter your first name: ")
userText2  = raw_input("Enter your last name: ")
result     = getCommonLetters(userText1, userText2)
numMatches = len(result)
if numMatches == 0:
    print "No matches."
else:
    print "Number of matches:", numMatches

for letter in result:
    print letter
  • 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-31T11:57:52+00:00Added an answer on May 31, 2026 at 11:57 am

    Try this:

    def CommonLetters(s1, s2):
        l1=list(''.join(s1.split()))
        l2=list(''.join(s2.split()))
        return [x for x in l1 if x in l2]
    
    print CommonLetters('Tom','Dom de Tommaso')    
    

    Output:

    >>> ['T', 'o', 'm']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question is, why I can not use hide() & show() to hide/show table
My question may not make sense but I have valid reason. We use .net
This question is not about 'best' barcode library recommendation, we use various products on
This question is NOT about race-conditions, atomicity, or why you should use locks in
In another Stack Overflow question Leon Timmermans asserted: I would advice you not to use
Coming from another question of mine where I learnt not to EVER use db
Original Question: i read that for RESTful websites. it is not good to use
QUESTION: Re use of .NET Backgroundworker, is there not a way to let exceptions
I have a question but I'm not sure of the word to use. My
Not sure this is a programming question, but we use LaTeX for all our

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.