sorting

Sorting list based on another list's order [duplicate]

为君一笑 提交于 2020-12-05 02:52:26
问题 This question already has answers here : Guava way of sorting List according to another list? (5 answers) Closed 3 years ago . I need to sort a list of Person objects( List<Person> , where each Person object has few attributes like id (unique), name , age … etc). The sorting order is based on another list. That list contains a set of Person id 's (A List<String> which is already sorted). What is the best way to order the List<Person> in the same order as the list of id 's using Kotlin or Java

In a bash script how to loop through files sorted by date

家住魔仙堡 提交于 2020-12-04 04:39:19
问题 I have the following script: #!/bin/sh HOST='host' USER='user@example.com' PASSWD='pwd' for FILE in *.avi do ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD binary put $FILE rm FILE quit done END_SCRIPT exit 0 How do I ensure that I process the oldest file first? I have seen a lot of hacks that use ls -t, but there has to be a simpler way. 回答1: I would modify your for loop with this: for FILE in `ls -tU *.avi` do # # loop content here with ${FILE} # done From the ls docs: -t

In a bash script how to loop through files sorted by date

我的梦境 提交于 2020-12-04 04:37:47
问题 I have the following script: #!/bin/sh HOST='host' USER='user@example.com' PASSWD='pwd' for FILE in *.avi do ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD binary put $FILE rm FILE quit done END_SCRIPT exit 0 How do I ensure that I process the oldest file first? I have seen a lot of hacks that use ls -t, but there has to be a simpler way. 回答1: I would modify your for loop with this: for FILE in `ls -tU *.avi` do # # loop content here with ${FILE} # done From the ls docs: -t

In a bash script how to loop through files sorted by date

前提是你 提交于 2020-12-04 04:37:46
问题 I have the following script: #!/bin/sh HOST='host' USER='user@example.com' PASSWD='pwd' for FILE in *.avi do ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD binary put $FILE rm FILE quit done END_SCRIPT exit 0 How do I ensure that I process the oldest file first? I have seen a lot of hacks that use ls -t, but there has to be a simpler way. 回答1: I would modify your for loop with this: for FILE in `ls -tU *.avi` do # # loop content here with ${FILE} # done From the ls docs: -t

Output from sort does not appear to be sorted

半世苍凉 提交于 2020-11-30 00:34:49
问题 I have the following text file (sort_test.txt): PGA_scaffold1__77 PGA_scaffold2__36 PGA_scaffold3__111 PGA_scaffold4__129 PGA_scaffold5__109 PGA_scaffold6__104 PGA_scaffold7__69 PGA_scaffold8__63 PGA_scaffold9__45 PGA_scaffold10__49 PGA_scaffold11__79 PGA_scaffold12__71 PGA_scaffold13__52 PGA_scaffold14__91 PGA_scaffold15__101 PGA_scaffold16__33 PGA_scaffold17__51 PGA_scaffold18__69 When I try to sort the file with the following code, the sort output seems to be out of order (specifically,

Divide numbers into unique sorted digits displayed in a label on a userform

与世无争的帅哥 提交于 2020-11-29 04:10:05
问题 I want to divide numbers into unique sorted digits. For example, the number can be 127425 and I would like 12457 as the result, meaning sorted and duplicate removed. I think the best is to explain with example: +---------+--------+ | Number | Result | +---------+--------+ | 127425 | 12457 | +---------+--------+ | 2784425 | 24578 | +---------+--------+ | 121 | 12 | +---------+--------+ | 22222 | 2 | +---------+--------+ | 9271 | 1279 | +---------+--------+ The longest result can be only

Divide numbers into unique sorted digits displayed in a label on a userform

一曲冷凌霜 提交于 2020-11-29 04:07:32
问题 I want to divide numbers into unique sorted digits. For example, the number can be 127425 and I would like 12457 as the result, meaning sorted and duplicate removed. I think the best is to explain with example: +---------+--------+ | Number | Result | +---------+--------+ | 127425 | 12457 | +---------+--------+ | 2784425 | 24578 | +---------+--------+ | 121 | 12 | +---------+--------+ | 22222 | 2 | +---------+--------+ | 9271 | 1279 | +---------+--------+ The longest result can be only

How to Sort this String in Ascending Alphanumeric

可紊 提交于 2020-11-28 03:22:30
问题 I have the following list of string var strTest = new List<string> { "B2", "B1", "B10", "B3" }; I want to sort them as follows "B1, B2, B3, B10". If I use LINQ OrderBy it sorts this way "B1, B10, B2, B3" Please help. Here's my code. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SortingDemo { class Program { static void Main(string[] args) { var strTest = new List<string> { "B2", "B1", "B10", "B3" }; var sort = strTest.OrderBy(x => x); var

Sorting strings by a substring in Python [duplicate]

…衆ロ難τιáo~ 提交于 2020-11-27 01:57:47
问题 This question already has answers here : python, sorting a list by a key that's a substring of each element (5 answers) Closed 15 days ago . I have a list of strings in python that looks like this: Name number number 4-digit number How can I sort it by the last number? 回答1: Like that: sorted(your_list, lambda x: int(x.split()[-1])) 回答2: my_list = ['abc 12 34 3333', 'def 21 43 2222', 'fgh 21 43 1111'] my_list.sort(key=lambda x:int(x.split()[-1])) my_list is now: ['fgh 21 43 1111', 'def 21 43

Sorting strings by a substring in Python [duplicate]

孤街浪徒 提交于 2020-11-27 01:57:16
问题 This question already has answers here : python, sorting a list by a key that's a substring of each element (5 answers) Closed 15 days ago . I have a list of strings in python that looks like this: Name number number 4-digit number How can I sort it by the last number? 回答1: Like that: sorted(your_list, lambda x: int(x.split()[-1])) 回答2: my_list = ['abc 12 34 3333', 'def 21 43 2222', 'fgh 21 43 1111'] my_list.sort(key=lambda x:int(x.split()[-1])) my_list is now: ['fgh 21 43 1111', 'def 21 43