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

The Archive Base Latest Questions

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

I’m trying to write a function that takes two string arguments and returns the

  • 0

I’m trying to write a function that takes two string arguments and returns the number of times a character from the first string occurs in the second string.

I am a complete beginner to python and am stumped. If anyone could point me in the right direction that would be great. I’ve been given this to start with:

def occurrences(text1, text2):
    """Return the number of times characters from text1 occur in text2

    occurrences(string, string) -> int
    """
    #Your code goes here

As you can see, 2 strings are needed. I thought that string 1 and string 2 would be sufficient but I have no idea how to to define them.

I have started with this so far and I’m not even having any success.

for c in "string":
    print c
    if c == char c in "string2":
        count += 1

I’m just throwing in random variables because how am I suppose to find char(A-Z) in a string that I dont even know?

EDIT: some of the tips you guys have told me i havn’t learned yet. For this question i should be using:

  • for loop
  • in

Some hints were given to me also:

Hint 1: You might find in useful for testing if one string is in another string.

Hint 2: Look at each character in the second argument and see if it is in the first argument.

  • 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-31T13:56:47+00:00Added an answer on May 31, 2026 at 1:56 pm

    Let’s start here and have a bit of a discussion:

    As you can see, 2 strings are needed. I thought that string 1 and string 2 would be sufficient but I have no idea how to to define them.

    They are provided for you: they are called text1 and text2. They come from the code that calls the functions. Were functions explained to you at some point? In your own words, how does a function work? What will the code look like that calls occurrences?

    (Hint for the last part: there is an example given on your assignment sheet.)

    Next:

    if c == char c in "string2":
    

    What do you expect this to mean? In particular, what do you expect char to mean? (Have you studied programming languages other than Python before?)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is

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.