Python Forum
how to print all data from all data array?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to print all data from all data array?
#1
Hello,
maybe the names is incorrect so I will show in example
x = [{'id': '*1F010121', 'name': 'hotspot/Fonts', 'type': 'directory', 'creation-time': 'may/06/2018 09:35:12'},
{'id': '*1F010221', 'name': 'hotspot/images', 'type': 'directory', 'creation-time': 'may/06/2028 09:35:12'}]
}
I want to print all the names of the directory he found

something like
***** I KNOW THIS IS NOT THE CORRECT COMMAND
foreach data in x:
    print(x["name"][data])
so I will get
hotspot/Fonts , hotspot/images

Thanks ,
Reply
#2
Don;t know how to remove the post

But after playing I have found the answer:
for names in response:
    print(names['name'])
    List_OF_Names.append(names['name'])
Reply
#3
I wrote a generic function to list dictionaries,
main() function shows how to display your data

def display_dict(dictname, level=0):
    indent = " " * (4 * level)
    for key, value in dictname.items():
        if isinstance(value, dict):
            print(f'\n{indent}{key}')
            level += 1
            self.display_dict(value, level)
        else:
            print(f'{indent}{key}: {value}')
        if level > 0:
            level -= 1


def main():
    x = [{'id': '*1F010121', 'name': 'hotspot/Fonts', 'type': 'directory', 'creation-time': 'may/06/2018 09:35:12'},
        {'id': '*1F010221', 'name': 'hotspot/images', 'type': 'directory', 'creation-time': 'may/06/2028 09:35:12'}]
    for item in x:
        print(display_dict(item))


if __name__ == '__main__':
    main()
Output:
id: *1F010121 name: hotspot/Fonts type: directory creation-time: may/06/2018 09:35:12 None id: *1F010221 name: hotspot/images type: directory creation-time: may/06/2028 09:35:12 None
Reply
#4
nice solution
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with to check an Input list data with a data read from an external source sacharyya 3 402 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  print(data) is suddenly invalid syntax db042190 6 1,183 Jun-14-2023, 02:55 PM
Last Post: deanhystad
  Write sql data or CSV Data into parquet file mg24 2 2,419 Sep-26-2022, 08:21 AM
Last Post: ibreeden
  Load multiple Jason data in one Data Frame vijays3 6 1,536 Aug-12-2022, 05:17 PM
Last Post: vijays3
  Issue in changing data format (2 bytes) into a 16 bit data. GiggsB 11 2,654 Jul-25-2022, 03:19 PM
Last Post: deanhystad
  Seeing al the data in a dataframe or numpy.array Led_Zeppelin 1 1,139 Jul-11-2022, 08:54 PM
Last Post: Larz60+
Question Change elements of array based on position of input data Cola_Reb 6 2,112 May-13-2022, 12:57 PM
Last Post: Cola_Reb
  Adding shifted data set to data set xquad 3 1,499 Dec-22-2021, 10:20 AM
Last Post: Larz60+
  Looking for data/info on a perticular data-proccesing problem. MvGulik 9 3,849 May-01-2021, 07:43 AM
Last Post: MvGulik
  How to filter out Column data From Multiple rows data? firaki12345 10 5,091 Feb-06-2021, 04:54 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020