Python Forum
Parse String between 2 Delimiters and add as single list items
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parse String between 2 Delimiters and add as single list items
(Apr-11-2021, 09:41 PM)bowlofred Wrote: Except for not having brackets around it, this appears to be valid JSON. I'd add the brackets and parse as JSON. That will give you a list of dicts that you can read.

import json

file = open('csdb.rss', mode='r')
json_string = "[" + + "]"
data = json.loads(json_string)
print(f"The first element is {data[0]}")

print("The keys and values in the first element are:")
for k, v in data[0].items():
    print(f"{k} => {v}")

ouch my Bad, i posted to the wring Subcategory. My python version is 2.7.18 There the Syntax is different and i get the error

File "F:\GP\C64\BBS\csdbrss\", line 34
print(f"The first element is {data[0]}")
SyntaxError: invalid syntax

Messages In This Thread
RE: Parse String between 2 Delimiters and add as single list items - by lastyle - Apr-11-2021, 09:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Delimiters - How to skip some html tags from being translate Melcu54 0 388 May-26-2021, 06:21 AM
Last Post: Melcu54
  Feed List items with Integer euras 9 836 May-19-2021, 07:45 PM
Last Post: snippsat
  Sum of list items tristanfermat 2 611 Feb-06-2021, 12:04 PM
Last Post: tristanfermat
  convert List with dictionaries to a single dictionary iamaghost 3 766 Jan-22-2021, 03:56 PM
Last Post: iamaghost
  How to append multiple <class 'str'> into a single List ahmedwaqas92 2 683 Jan-07-2021, 08:17 AM
Last Post: ahmedwaqas92
  Undo interation to make a single list? DustinKlent 2 608 Nov-29-2020, 03:41 AM
Last Post: DustinKlent
  Count number of occurrences of list items in list of tuples t4keheart 1 682 Nov-03-2020, 05:37 AM
Last Post: deanhystad
  concatenating 2 items at a time in a python list K11 3 696 Oct-21-2020, 09:34 AM
Last Post: buran
  Using lambdas and map() to parse substrings in a single line Drone4four 5 1,220 Sep-20-2020, 10:38 AM
Last Post: snippsat
  Select the other of 2 items in a list Clunk_Head 7 1,164 Sep-01-2020, 05:27 PM
Last Post: Clunk_Head

Forum Jump:

User Panel Messages

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