python, sorting a dict/json

Ed plug at 0x1b.com
Fri Feb 22 18:40:42 MST 2019


Hans - have you tried jq?
https://stedolan.github.io/jq/


On Fri, Feb 22, 2019 at 12:21 PM der.hans <PLUGd at lufthans.com> wrote:
>
> moin moin,
>
> I'm trying to sort some data that is currently in json being imported into
> a dict.
>
> It's essentially bibliography information, but without a unique ID.
>
> I mostly want to sort on publication date, but also want to group by
> publication. There could be multiple publications on the same date.
>
> Currently using a json format like:
>
> {
>   "pubs": [
>    {
>     "date": 20190222
>     "title": "a title"
>     "url": "https://some.domain/page.html"
>    },
>    {
>     "date": 20190221
>     "title": "another title"
>     "url": "https://some.other.domain/page.html"
>    }
>   ]
> }
>
> Format can change if that helps.
>
> I want to be able to display items in order. Mostly chronological, but
> also by other details.
>
> Any suggestions for how to sort them for display?
>
> A nice, but not required, feature would be sorting them for saving to disk
> as well.
>
> ciao,
>
> der.hans
> --
> #  https://www.LuftHans.com   https://www.PhxLinux.org
> # "You want weapons? We're in a library! Books! The best weapons in the
> # world! This room's the greatest arsenal we could have - arm yourselves!"
> # -- the Doctor: Doctor Who, Tooth and Claw, 2006
> ---------------------------------------------------
> PLUG-discuss mailing list - PLUG-discuss at lists.phxlinux.org
> To subscribe, unsubscribe, or to change your mail settings:
> https://lists.phxlinux.org/mailman/listinfo/plug-discuss


More information about the PLUG-discuss mailing list