I have a sequence generated by list comprehension as follows:
var a_bigram_list = lc[a[i..i+2] | (i <- 0..<len(a)), string]
Now, I would like to sort it but sort(a_bigram_list)
will result in the following compilation error
Error: type mismatch: got (seq[string])
but expected one of:
proc sort[A, B](t: OrderedTableRef[A, B]; cmp: proc (x, y: (A, B)): int)
proc sort[A, B](t: var OrderedTable[A, B]; cmp: proc (x, y: (A, B)): int)
proc sort[A](t: CountTableRef[A])
proc sort[A](t: var CountTable[A])
proc sort[T](a: var openArray[T]; cmp: proc (x, y: T): int; order = SortOrder.Ascending)
Is there any way of sorting a sequence? Or do I need to convert it to array? If so, can is there a way to obtain an array from lc?
sort
works with sequences (openArray
is a generic parameter type that accepts both array
s and seq
s), but it expects a comparison proc as a second parameter.
You can provide it a default cmp from system module:
sort(a_bigram_list, system.cmp)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With