I have a list
list={{ω->0.538826+1.31221 I},{ω->-0.538826+1.31221 I},{ω->-1.2444-0.68023 I},{ω->1.2444-0.68023 I},{ω->0.496864+1.32811 I},{ω->-0.496864+1.32811 I},{ω->1.22187-0.719147 I},{ω->-1.22187-0.719147 I},{ω->0.454442+1.34261 I},{ω->-0.454442+1.34261 I},{ω->1.19811-0.757303 I},{ω->-1.19811-0.757303 I},{ω->1.17316-0.794657 I},{ω->-1.17316-0.794657 I},{ω->0.411617+1.35568 I},{ω->-0.411617+1.35568 I},{ω->-1.14704-0.831174 I},{ω->1.14704-0.831174 I}}
and I would like to sort it by ascending positive. I tried with the Sort command
Sort[list, (Re[#1[[1, 2]]] < Re[#2[[1, 2]]] && Re[#1[[1, 2]]] > 0) &]
but it does not sort them in desired order:
{{ω->1.14704-0.831174 I},{ω->-1.14704-0.831174 I},{ω->-0.411617+1.35568 I},{ω->0.411617+1.35568 I},{ω->-1.17316-0.794657 I},{ω->1.17316-0.794657 I},{ω->-1.19811-0.757303 I},{ω->1.19811-0.757303 I},{ω->-0.454442+1.34261 I},{ω->0.454442+1.34261 I},{ω->-1.22187-0.719147 I},{ω->1.22187-0.719147 I},{ω->-0.496864+1.32811 I},{ω->0.496864+1.32811 I},{ω->1.2444-0.68023 I},{ω->-1.2444-0.68023 I},{ω->-0.538826+1.31221 I},{ω->0.538826+1.31221 I}}
How am I wrong?
Thanks in advance
&& Re[#1[[1, 2]]] > 0
part makes this not be a "valid" ordering i.e. the outcome will depend on the initial order of the list (and sorting algorithm used). $\endgroup$SortBy[list, -Abs[Re[ω /. #]] &]
doesn't match your desired output $\endgroup$