Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with list thing please
#1
So I'm trying to get both of the ["name"] in this list and have them put into a txt file

[{'id': 2124447617, 'name': 'Welcome To The Generator', 'description': 'Thanks for joining our generator', 'enabled': True, 'iconImageId': 2687851451, 'awarder': {'id': 2101105173, 'type': 'Place'}, 'statistics': {'pastDayAwardedCount': 163, 'awardedCount': 41664, 'winRatePercentage': 1.0}, 'created': '2018-12-28T20:05:03.977Z', 'updated': '2018-12-28T20:05:03.977Z'}, {'id': 2124456449, 'name': '1 Minute Played', 'description': 'very cool 1 min', 'enabled': True, 'iconImageId': 2894312587, 'awarder': {'id': 2101105173, 'type': 'Place'}, 'statistics': {'pastDayAwardedCount': 148, 'awardedCount': 20791, 'winRatePercentage': 1.0}, 'created': '2019-02-24T23:29:37.117Z', 'updated': '2019-02-25T02:21:27.083Z'}]
How would I be able to?

sorry im bad at python
Reply
#2
It look like a part coming from JSON,and then it's not normal to start with list.
Anyway here format with black,then is easier to see the structure.
lst = [
    {
        "id": 2124447617,
        "name": "Welcome To The Generator",
        "description": "Thanks for joining our generator",
        "enabled": True,
        "iconImageId": 2687851451,
        "awarder": {"id": 2101105173, "type": "Place"},
        "statistics": {
            "pastDayAwardedCount": 163,
            "awardedCount": 41664,
            "winRatePercentage": 1.0,
        },
        "created": "2018-12-28T20:05:03.977Z",
        "updated": "2018-12-28T20:05:03.977Z",
    },
    {
        "id": 2124456449,
        "name": "1 Minute Played",
        "description": "very cool 1 min",
        "enabled": True,
        "iconImageId": 2894312587,
        "awarder": {"id": 2101105173, "type": "Place"},
        "statistics": {
            "pastDayAwardedCount": 148,
            "awardedCount": 20791,
            "winRatePercentage": 1.0,
        },
        "created": "2019-02-24T23:29:37.117Z",
        "updated": "2019-02-25T02:21:27.083Z",
    },
]
>>> lst[0]['name']
'Welcome To The Generator'
>>> # Then both name would be
>>> [i['name'] for i in lst]
['Welcome To The Generator', '1 Minute Played']
Try to put in .txt file yourself,post back if have trouble.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I am confused with the key and value thing james1019 3 912 Feb-22-2023, 10:43 PM
Last Post: deanhystad
  Need help i just started the whole thing gabriel789 16 3,098 Sep-12-2022, 08:04 PM
Last Post: snippsat
  i making a terminal sign up website thing Kenrichppython 1 1,659 Nov-04-2021, 03:57 AM
Last Post: bowlofred
  use thing before self sylvanas 3 2,305 Jul-21-2021, 04:54 PM
Last Post: sylvanas
  Not able to make a specific thing pause in pygame cooImanreebro 4 3,145 Dec-13-2020, 10:34 PM
Last Post: cooImanreebro
  Printing one thing from a list bidoofis 1 2,309 Feb-05-2019, 09:02 PM
Last Post: ichabod801
  I found weird thing. catastrophe_K 1 2,062 Sep-29-2018, 09:59 AM
Last Post: gruntfutuk
  Make one thing act like another Zman350x 2 2,165 Aug-16-2018, 06:45 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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