Ruby: Sorting an array of strings, in alphabetical order, that includes some arrays of strings
Tag : ruby , By : PaulPlum
Date : March 29 2020, 07:55 AM
hope this fix your issue Say I have: , I think this is what you want: a.sort_by { |f| f.class == Array ? f.first : f }
|
Print in Value order, or if values are the same, alphabetical order
Tag : python , By : Ben Humphrys
Date : March 29 2020, 07:55 AM
With these it helps I am trying to make a 'Vowel Counter', but I would like it to satisfy the following conditions. , How about: " ".join("{}:{}".format(v, x[v]) for v in sorted(vowels, key=x.get, reverse=True))
{'a':2, 'e':5, 'i':6, 'o':4, 'u':2} -> i:6 e:5 o:4 a:2 u:2
{'a':7, 'e':7, 'i':1, 'o':1, 'u':3} -> a:7 e:7 u:3 i:1 o:1
|
print array in struct in alphabetical order and in descending order
Tag : swift , By : August
Date : March 29 2020, 07:55 AM
help you fix your problem There's 2 ways you can do this. Both would require you to pass your array to sort (Swift 2), now sorted (Swift 3). struct MyData {
var company = String()
var score: Int
}
let data = [
MyData(company: "smiths", score: 4),
MyData(company: "lukes", score: 4),
MyData(company: "lukes", score: 9)
]
let sortedArray = data.sorted(by: { ($0.company, $1.score) < ($1.company, $0.score) })
struct MyData {
var company = String()
var score: Int
}
extension MyData: Equatable {
static func ==(lhs: MyData, rhs: MyData) -> Bool {
return (lhs.company, lhs.score) == (rhs.company, rhs.score)
}
}
extension MyData: Comparable {
static func <(lhs: MyData, rhs: MyData) -> Bool {
return (rhs.company, lhs.score) > (lhs.company, rhs.score)
}
}
let data = [
MyData(company: "smiths", score: 4),
MyData(company: "lukes", score: 4),
MyData(company: "lukes", score: 9)
]
let sortedArray = data.sorted()
|
Alphabetical Order for all Localizable Strings
Date : March 29 2020, 07:55 AM
this one helps. You are ordering them by the keys at the moment, not the values. Since you need the keys for the images and the value for the labels, and you want to sort the rows by the values, you need more than just the array of keys. let animals = ["A1", "A2", "A3", "A4", "A5"].map { ($0, NSLocalizedString($0, comment: "")) }.sorted { $0.1 < $1.1 }
cell.textLabel?.text = animals[indexPath.row].1
cell.smallBird.image = UIImage(named: animals[indexPath.row].0)
|
Concatenate Strings in Alphabetical Order
Date : March 29 2020, 07:55 AM
|