Problems with dictionaries and lists - python

0

Hello, I have the following dictionary.

    datas = {'records': [{'createdTime': '2018-02-20T21:56:20.288Z',
       'fields': {'publicacao': '2018-01-22'},
       'id': 'rec1c1c8qyIkdwyMD'},
      {'createdTime': '2018-02-20T21:56:20.288Z',
       'fields': {'publicacao': '2018-01-29'},
       'id': 'rec2ZzEckjEvtHeL9'},
      {'createdTime': '2018-02-20T21:56:50.166Z',
       'fields': {'publicacao': '2017-10-16'},
       'id': 'rec2qlE8kVgjjJC5I'},
      {'createdTime': '2018-02-20T22:17:46.301Z',
       'fields': {'publicacao': '2018-02-05'},
       'id': 'rec3RXluN3xw8MOf1'},
      {'createdTime': '2018-02-20T21:56:50.166Z',
       'fields': {'publicacao': '2017-10-23'},
       'id': 'rec5H0UvSqLdrGpl5'},
      {'createdTime': '2018-02-20T21:56:50.166Z',
       'fields': {'publicacao': '2017-11-20'},
       'id': 'rec83xBDXZ8Cne8H7'},
      {'createdTime': '2018-02-20T21:56:50.166Z',
       'fields': {'publicacao': '2017-12-22'},
       'id': 'recHhm6vB8TrHGy93'},
      {'createdTime': '2018-02-20T21:56:20.288Z',
       'fields': {'publicacao': '2018-01-15'},
       'id': 'recHmVeJ5nkALuryh'},
      {'createdTime': '2018-02-20T21:56:50.166Z',
       'fields': {'publicacao': '2017-11-27'},
       'id': 'recOajfC1FGtPlmsn'},
      {'createdTime': '2018-02-20T21:56:50.166Z',
       'fields': {'publicacao': '2017-11-06'},
       'id': 'recUNJhuNDYOJ1eaj'},
      {'createdTime': '2018-02-20T21:56:50.166Z',
       'fields': {'publicacao': '2017-11-13'},
       'id': 'recWO44hmzjzhcLfm'},
      {'createdTime': '2018-02-20T21:56:50.166Z',
       'fields': {'publicacao': '2017-12-19'},
       'id': 'recXITnVKRsBPhxCb'},
      {'createdTime': '2018-02-20T21:56:50.166Z',
       'fields': {'publicacao': '2017-12-11'},
       'id': 'rece5u18FUTlCwnC7'},
      {'createdTime': '2018-02-20T21:56:50.166Z',
       'fields': {'publicacao': '2017-12-04'},
       'id': 'receT9LqJ8zFbkbVW'},
      {'createdTime': '2018-02-20T21:56:50.166Z',
       'fields': {'publicacao': '2017-10-09'},
       'id': 'rechssorYxXi8Grdp'},
      {'createdTime': '2018-02-20T21:56:50.166Z',
       'fields': {'publicacao': '2017-10-30'},
       'id': 'recvdSdCxqXz4hbbh'}]}

I wanted to create a list with just the date fields. I tried something like this:

    base_de_relatorio = []
    for v in datas['records']:
        base_de_relatorio.append(v['fields'])

The problem is that in this way the name "publication comes together ({'publication': '2018-01-22').) I just need a list with all the dates.

Does anyone know how to solve it?

    
asked by anonymous 20.02.2018 / 23:30

1 answer

0

You can do this:

datas_publicacao = [e['fields']['publicacao'] for e in datas['records']]

and the return will be:

['2018-01-22', '2018-01-29', '2017-10-16', '2018-02-05', '2017-10-23', '2017-11-20', '2017-12-22', '2018-01-15', '2017-11-27', '2017-11-06', '2017-11-13', '2017-12-19', '2017-12-11','2017-12-04', '2017-10-09', '2017-10-30']
    
21.02.2018 / 10:12