Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
2 votes
1 answer
4k views

Python script for sorting a huge log file based on timestamps

I want to write a python script to sort a huge file, say 2 GB in size, which contains logs in the following format - ...
user168115's user avatar
2 votes
1 answer
93 views

Most efficient way to find spatial order from a list of tuples (Python)

I have a circle-growth algorithm (line-growth with closed links) where new points are added between existing points at each iteration. The linkage information of each point is stored as a tuple in a ...
solub's user avatar
  • 123
5 votes
1 answer
95 views

Sorting software version list using Python 2.7 (no modules)

I am participating in a challenge and one of the challenges was to write a script to sort a list of software versions (ex: 1.0, 1.3.2, 12, 1.3.0). Here is the my solution: ...
user40929's user avatar
  • 163
3 votes
1 answer
64 views

Sorting by checking 2 distance away elements in a list, and check the method's accuracy

This code works as follows : It accepts number of test case T. For each test case, it accepts length of sequence of integers N and the sequence (or list) itself L. The goal is to sort the list by ...
Redsbefall's user avatar
  • 1,142
8 votes
2 answers
604 views

Class for sorting pool balls

I have written this code for fun. I'd like to hear your suggestions about how to make it more compact and pythonic. ...
Pitto's user avatar
  • 829
4 votes
2 answers
654 views

Bubble Sorting Algorithm

I made a simple Python program which takes a list of unique numbers and orders them from smallest to greatest. The algorithm (which is actually quite similar to bubble sort) works like this: Take the ...
Anthony Pham's user avatar
2 votes
2 answers
2k views

Sort array by low, medium and high

I'm working on a problem to sort array by low, medium and high -- in-place tweak original array. I'm looking for advice, especially any algorithm implementation efficiency. My current bottleneck of ...
Lin Ma's user avatar
  • 3,453
2 votes
1 answer
100 views

Find valid triples for a sorted list of integers (part 2)

Have some ideas to improve code from this discussion (Find valid triples for a sorted list of integers) and post new code in a new post. The new idea is to try to remember where low bound searched ...
Lin Ma's user avatar
  • 3,453
4 votes
1 answer
14k views

Sorting two lists

This sorts two lists (a, b) according to aand returns two sorted lists separately: ...
Roman's user avatar
  • 143
4 votes
1 answer
2k views

Checking to see if array can be sorted using only one operation

I'm doing this HackerRank problem, which asks whether an array of up to 100000 integers can be sorted in ascending order by exactly one of the following: swapping two elements reversing a subarray ...
Sidharth Samant's user avatar
1 vote
2 answers
2k views

Compare function for lists

I need to sort a list of lists. The following is a compare function: ...
Loom's user avatar
  • 555
4 votes
4 answers
14k views

Checking whether a list is sorted, ascending or descending

What is the best way to conditionally use an operator? All 3 methods seemed acceptable to me, and the last 2 better. If you're curious: I've got a list which is unsorted, and many other lists which ...
12345678910111213's user avatar
2 votes
1 answer
607 views

Binary search function

I have written this function to perform a binary search on an array, given begin/end indices and a value to look for in the supplied array: ...
Lin Ma's user avatar
  • 3,453
7 votes
2 answers
767 views

Shell sort function

I wrote a Python sort function that uses shell sort: ...
The Turtle's user avatar
6 votes
1 answer
184 views

Multiprocess Bogosort

I only program by hobby, and I'm trying to improve with Python, so along with practicing coding I decided to venture into multiprocessing. This is a command line and will sort a variable number of ...
Brandon's user avatar
  • 161
4 votes
1 answer
10k views

Sorting a list of names by greatest lexicographical order

This is a puzzle I found online that I have been trying to optimize and make the best version. I've tested it and it works great but I'm curious how it can be improved in any way. Instructions: "...
Tim's user avatar
  • 43
2 votes
2 answers
2k views

Bubble sort a list of integers for a number of iterations

I wrote a program for this problem, but it stopped because it took too much time. Any tips? The Problem: Bubble sort is the simplest algorithm for elements sorting. At each iteration we sequentially ...
possibility0's user avatar
4 votes
2 answers
2k views

Custom sorting a list of objects efficiently

I'm trying to make sorting of objects in my program as fast as possible. I know that sorting with a cmp function is deprecated in python 3.x and that using keys is faster, but I'm not sure how to get ...
maxbart's user avatar
  • 113
7 votes
2 answers
871 views

Pythonic quicksort algorithm

Is my implementation of quicksort efficient, in-place, pythonic ? ...
eightnoteight's user avatar
0 votes
3 answers
379 views

Better sorting speed

import sys x=int(sys.stdin.readline()) lst = [int(sys.stdin.readline()) for i in xrange(x)] lst.sort() print lst How can I make this code faster for large ...
shubham's user avatar
  • 361
7 votes
1 answer
221 views

Out of order class resequencer

I got bored recently and wrote a tool to re-order out of order classes in Python files. This can occur with some auto-generation code tools for databases and the like; these files can sometimes be ...
dilbert's user avatar
  • 171