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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:23:21+00:00 2026-06-13T12:23:21+00:00

Suppose I’m writing a simple parser. It has a dispatcher, which calls the corresponding

  • 0

Suppose I’m writing a simple parser. It has a dispatcher, which calls the corresponding parsing functions depending on the type of the input expression.

def dispatcher(expression):
    m = pattern1.match(expression):
    if m is not None:
        handle_type1(expression, m)
    # ... other types

My question is, is there anyway to combine the matching and checking for None? I mean, something like the following C code:

void dispatcher(char *expression)
{
    if ((m = pattern1.match(expression)) != NULL) {
        // ... handle expression type 1
    }
    else if ((m = pattern2.match(expression)) != NULL) {
        // ... handle expression type 2
    }
    // ... other cases
}

Thanks!

  • 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-13T12:23:22+00:00Added an answer on June 13, 2026 at 12:23 pm

    This isn’t really about combining pattern matching with checking for none, it’s about whether you can assign to a variable and evaluate the result of that assignment in one expression, because pattern.match() call could be any function returning a value.

    And the answer in general is no, because in Python assignment is a statement, not an expression as it is in C.

    The only difference I can see in this case is that you save yourself an extra carriage return, which isn’t so useful. The assign-and-compare idiom is more useful in loops, but in Python you just have to do it over two lines (using break if necessary).

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

Sidebar

Related Questions

Suppose a simple network model: A has successfully created a TCP connection to B,
suppose I have a table which has a column days('mon','tue','wed','thu','fri'), how do I implement
Suppose I have a simple model, such as Record: @Model public class Record {
Suppose I have this line of code, which loads 16 x 8-bit unsigned integer
Suppose application has multiple apks for different countries. If US user with international roaming
Suppose a scenario like below : Class User {} // User has Admin Role
Suppose I have a ASP.NET Web API controller that uses a service, which in
Suppose I have two pages: - page 1 uses jquery mobile and has a
Suppose I have a dictionary a which is a = {'a':1,'b':2,'c':3,'d':4,'e':5} Now If I
Suppose you're developing a software product that has periodic releases. What are the best

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.