I’m trying to print in ascending order a 1GB file containing a randomly generated big number. This is the code that I’m using to generate the random number for my test (found it here). The following python code works OK and takes a bit less than 4 minutes. But I was told this can be accomplished i…
Tag: sorting
How to rename files chronologically without changing their order?
I made an application in Python (link for source code at the bottom) which renames files (in a directory) by sorting them (based on their extension) into one of these: Image, Video, Text, GIF, Audio and Unknown Extension. Basically, it loops through a directory, gets all the files in it, sorts them, for each …
How to reorder pandas dataframe based off list containing column order
Say I have a dataframe ‘df’ that contains a list of files and their contents: How can I reorder this df if I have ordered lists of how the ‘Field’ column should be ordered? So that the resulting df is re ordered like so (I am not trying to just sort ‘Field’ in reverse alpha…
Sort in nested dict by summing values python pandas
I have nested dict something like that I need sort on the level “code” with depending on summing values “brands”. For example, *# ‘code2.2’ first because 2+1+25=28 > 2+8+5+4=19 # ‘code3’ first because 1+2=3 > 2 I can sum values “brands” by R…
Sort a number by its digits
I have to sort a vector of integers (all integers have the same length). Integers with the same first digit must be sorted in relation to the second digits, and numbers with the same: first and second digits are sorted by third digit etc. Also, the subsequent digits are sorted alternately (once ascending and …
How to delete values in a dict based on the presence of child values
I have a dict that looks like this: How can I iterate over the elements of this dict, and exclude any element that has “‘parent’ : None” and no child element (meaning, no other element in this dict has this one as a parent). Expected output: Answer I think this function can help you To…
Trouble sorting list of lists in Python with Insertion Sort
I am currently making a Python program which takes in the name of a grocery item, the aisle it’s on, its location along the aisle, and the price. It holds the data in a list of lists, with each inner list containing 4 elements. The program attempts to create the optimal route through the aisles, with tr…
(python) quicksort working for ordered data, but not for unordered data
I am working on an implementation of recursive quicksort in python. I am working with very large data sets (10,000 – 1,000,000 elements). When feeding it ordered data (i.e. changing an array sorted from largest -> smallest to smallest -> largest) it works fine. But when giving it unordered data, i…
Ordering a two-dimensional array relative to the main diagonal
Given a two-dimensional array T of size NxN, filled with various natural numbers (They do not have to be sorted in any way as in the example below.). My task is to write a program that transforms the array in such a way that all elements lying above the main diagonal are larger than each element lying on the …
How to rearrange the sample order of a torch dataloader?
I have a “torch.utils.data.DataLoader”. I want to rearrange the order of the samples. Is it possible? Answer Yes, you can use torch.utils.data.Subset and specify the indices.