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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:58:09+00:00 2026-06-12T11:58:09+00:00

In coding competitions we encounter inputs like: 2 3 4 5 So we do

  • 0

In coding competitions we encounter inputs like:

2 3

4 5

So we do the following:

m, n = [int(x) for x in raw_input().split(' ')]

Is there a faster way of doing the same thing?

  • 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-12T11:58:10+00:00Added an answer on June 12, 2026 at 11:58 am

    For all practical purposes, That’s about as fast as you can get. On some machines, you may see a speedup on the order or a couple percent if you go with map instead of a list comprehension, but that’s not guaranteed.

    Here’s some quick timings on my machine:

    from itertools import imap
    #map
    >>> timeit.timeit('x,y = map(int,line.split(" "))','from __main__ import line')
    4.7857139110565186
    >>> timeit.timeit('x,y = map(int,line.split())','from __main__ import line')
    4.5680718421936035
    #list comprehension
    >>> timeit.timeit('x,y = [int(x) for x in line.split(" ")]','from __main__ import line')
    4.3816750049591064
    >>> timeit.timeit('x,y = [int(x) for x in line.split()]','from __main__ import line')
    4.3246541023254395
    #itertools.imap
    >>> timeit.timeit('x,y = imap(int,line.split(" "))','from __main__ import line,imap')
    4.431504011154175
    >>> timeit.timeit('x,y = imap(int,line.split())','from __main__ import line,imap')
    4.3257410526275635
    #generator expression
    >>> timeit.timeit('x,y = (int(x) for x in line.split(" "))','from __main__ import line')
    4.897794961929321
    >>> timeit.timeit('x,y = (int(x) for x in line.split())','from __main__ import line')
    4.732620000839233
    

    Surprisingly, split() seems to perform better than split(" ").


    If you’re guaranteed to have ascii input of numbers between 0 and 9, you can do a good bit better using ord:

    >>>timeit.timeit('x,y = [ord(x)-48 for x in line.split(" ")]','from __main__ import line')
    1.377655029296875
    >>> timeit.timeit('x,y = [ord(x)-48 for x in line.split()]','from __main__ import line')
    1.3243558406829834
    

    But that imposes a severe restriction on your inputs.


    One other idea that you could try (I have no idea what the performance implications would be), but you could read your lines from sys.stdin:

    import sys
    for line in sys.stdin:
        x,y = [ord(x)-48 for x in line.split()]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I might be doing a coding competition soon, I was wondering if anyone made
Coding footer naively, if there's not enough content, then there will be empty space
The coding like decimal prodprice = Convert.ToDecimal(NavigationContext.QueryString[Price]); then what should i put for Binary
This coding i got from here. I get error in log cat view like
Do coding this way pose any security risks? $test = $_GET['test']; if($test) { $sql
Coding a new 3D engine is fascinating but I there are so many out
Coding for PHP on Mac OSX Lion, using the following within the httpd.conf file:
When coding in Java in Eclipse, is there a shortcut similar to typing syso
Coding Platform: ASP.NET 4.0 C# Consider the following scenario. I am uploading a file
Coding in C: typedef struct { char *string; int one; int two; } Example;

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.