I have a Map (datatype) with the following data structure:
var timePassedCamerasetB = mutable.Map.empty[String, Time];
It contains a String and a 'Time' object. The 'Time' object is made up from my own class. Below you can see what it consists of:
case class Time(daysSinceEpoch: Int, hours: Int, minutes: Int, seconds: Double)
I have saved all my data into this 'Map' variable. But there is one problem: I want to sort the values in this 'Map' variable based on multiple things, but I can't find any way to make it work.
For example. I have stored the following data within this map:
PP-33-XX -> Time(18492,3,7,0.0)
BA-12-PW -> Time(18492,9,0,40.0)
MM-11-OW -> Time(18492,3,7,16.0)
NX-66-PP -> Time(18492,3,6,30.0)
LA-53-NY -> Time(18492,9,0,56.0)
I want to sort the values in order (earliest time to latest time). This includes comparing multiple factors. First compare each daysSinceEpoch, then hours, minutes and seconds.
I want to transform the map into the following down below:
NX-66-PP -> Time(18492,3,6,30.0)
PP-33-XX -> Time(18492,3,7,0.0)
MM-11-OW -> Time(18492,3,7,16.0)
BA-12-PW -> Time(18492,9,0,40.0)
LA-53-NY -> Time(18492,9,0,56.0)
Does anyone know of an efficient way to do this? Unfortunately I can't..
Mapsare unordered collections by nature, why do you care about the order? Anyways, you probably will end up using a sequence like aListand then useorderByMaps don't have ordering, but specific implementations can either preserve insertion order (likeListMaps orLinkedHashMaps) or maintain ordering by key (likeTreeSets). I'm not aware ofMapimplementations in the standard library that maintain ordering by value.pattern = "|".join(list_of_words). Then usedf.Clean_text.str.count(pattern). This should give you what you were looking for.