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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:44:50+00:00 2026-06-06T19:44:50+00:00

I am trying to learn Python. Consider this simple anagram checker in C: bool

  • 0

I am trying to learn Python. Consider this simple anagram checker in C:

bool are_anagrams(const char* str1, const char* str2)
{
  int str1_count[NUM_CHARS] = {0};
  int str2_count[NUM_CHARS] = {0};

  for(int i = 0; i < strlen(str1); i++)
  {
    str1_count[str1[i] - 'a']++;
  } 
  for(int i = 0; i < strlen(str2); i++)
  {
    str2_count[str2[i] - 'a']++;
  }

  for(int i = 0; i < NUM_CHARS; i++)
  {
    if(str1_count[i] != str2_count[i])
      { return false; }
  }

  return true;
}

Specifically, how is the line str1_count[str2[i] - 'a']++ done in Python?

  • 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-06T19:44:51+00:00Added an answer on June 6, 2026 at 7:44 pm

    Or even better,

    def are_anagrams(s1, s2):
        return sorted(s1)==sorted(s2)
    

    .

    Edit: in response to @gnibbler:

    Here’s a quick run-time comparison, where x axis gives string length; blue is your function, green is mine. Both look pretty linear to me.

    graph comparing function run-times

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

Sidebar

Related Questions

I am trying to learn how to use threads with python. this is the
I'm trying to learn python and delving into string functions. As a simple example,
I'm trying to learn how to do XPath queries from Python using this sample
I'm trying learn Python (3 to be more specific) and I'm getting this error:
I am trying to learn Python lists. In this code I am trying to
This probably measures how pythonic you are. I'm playing around trying to learn python
I am trying to learn python and get good at algorithms. This is my
Hi im trying to learn Python and have a err i can understand ,
I have been trying to learn python over the last couple of months and
I'm trying to learn python and I'm attempting a hangman game. But when I

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.