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

  • Home
  • SEARCH
  • 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 9180099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:57:46+00:00 2026-06-17T17:57:46+00:00

I have a text file includes over than 10 million lines. Lines like that:

  • 0

I have a text file includes over than 10 million lines. Lines like that:

37024469;196672001;255.0000000000
37024469;196665001;396.0000000000
37024469;196664001;396.0000000000
37024469;196399002;85.0000000000
37024469;160507001;264.0000000000
37024469;160506001;264.0000000000

As you seen, delimiter is “;”. i would like to sort this text file by using python according to the second element. I couldnt use split function. Because it causes MemoryError. how can i manage it ?

  • 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-17T17:57:47+00:00Added an answer on June 17, 2026 at 5:57 pm

    Don’t sort 10 million lines in memory. Split this up in batches instead:

    • Run 100 100k line sorts (using the file as an iterator, combined with islice() or similar to pick a batch). Write out to separate files elsewhere.

    • Merge the sorted files. Here is an merge generator that you can pass 100 open files and it’ll yield lines in sorted order. Write to a new file line by line:

      import operator
      
      def mergeiter(*iterables, **kwargs):
          """Given a set of sorted iterables, yield the next value in merged order
      
          Takes an optional `key` callable to compare values by.
          """
          iterables = [iter(it) for it in iterables]
          iterables = {i: [next(it), i, it] for i, it in enumerate(iterables)}
          if 'key' not in kwargs:
              key = operator.itemgetter(0)
          else:
              key = lambda item, key=kwargs['key']: key(item[0])
      
          while True:
              value, i, it = min(iterables.values(), key=key)
              yield value
              try:
                  iterables[i][0] = next(it)
              except StopIteration:
                  del iterables[i]
                  if not iterables:
                      raise
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file of HTML that includes the following marker set for
I have text file with some stuff that i would like to put into
I have text file with something like first line line nr 2 line three
I have Text file that contains data separated with a comma , . How
I have text file, like FILED AS OF DATE: 20090209 DATE AS OF CHANGE:
I have text file with entries like 123 112 3333 44 2 How to
I' ve got a problem with Haskell. I have text file looking like this:
I have a text file that I want to edit by rewriting it to
I have a text file, its the content from a mail body.it includes html
I have a text ( .txt ) file that contains Java code! I want

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.