import re
import json

def unquote(text):
    if len(text) == 0 or text[0] != '"' or text[-1] != '"':
        return text

    try:
        return json.loads(text)
    except Exception:
        return text

# 增强后的正则表达式以支持所有 JSON 形式和普通文字
# Enhanced regular expression to support all JSON formats and plain text
re_param_code = r'\s*(\w[\w \-/]+):\s*({.*?}|\[.*?\]|"(?:\\.|[^\\"])*"|[^,]*)(?:,|$)'
re_param = re.compile(re_param_code)
re_imagesize = re.compile(r"^(\d+)x(\d+)$")

# 示例输入
lastline = '''
Steps: 20, Sampler: DPM++ 2M Karras, CFG scale: 7, Seed: 557152044, Size: 512x768, Model hash: 5307b134ff, Model: geminixMixRealistic_bV10, VAE hash: df3c506e51, VAE: kl-f8-anime2.ckpt, ADetailer model: PitHandDetailer-v1-seg.pt, ADetailer prompt: "(otherworldly), highly insanely detailed, masterpiece, top quality, best quality, highres, 4k, 8k, RAW photo, (very aesthetic, beautiful and aesthetic), (perfect face, beautiful face, perfect lips, perfect mouth, perfect detailed leg, beautiful detailed leg, perfect accurate limb, perfect beautiful *****, perfect body, perfect anatomy), (perfect hands, perfect hand anatomy, perfect finger, beautiful finger, perfect hands, good hands:1.2), beautiful and aesthetic, (otherworldly), highly insanely detailed, masterpiece, top quality, best quality, highres, 4k, 8k, RAW photo, (very aesthetic, beautiful and aesthetic), 1girl, solo, \nTower13_Gizelle, \na beautiful elvish girl, \n<lora:UnderGround-CP:1>, \nCar Parking,road,concrete,parking, \npure blue background,transparent background, \n \ndark_skin, tan_skin, tanned skin, dark skin, dark-skinned, black-skinned, bronze skin, \n(salt and pepper hair,red brown hair,), (fantasy world), (fantasy world)", ADetailer confidence: 0.3, ADetailer dilate erode: 4, ADetailer mask blur: 4, ADetailer denoising strength: 0.4, ADetailer inpaint only masked: True, ADetailer inpaint padding: 32, ADetailer ControlNet model: Passthrough, ADetailer model 2nd: face_yolov8n_v2.pt, ADetailer prompt 2nd: "(otherworldly), highly insanely detailed, masterpiece, top quality, best quality, highres, 4k, 8k, RAW photo, (very aesthetic, beautiful and aesthetic), (perfect face, beautiful face, perfect lips, perfect mouth, perfect detailed leg, beautiful detailed leg, perfect accurate limb, perfect beautiful *****, perfect body, perfect anatomy), (perfect hands, perfect hand anatomy, perfect finger, beautiful finger, perfect hands, good hands:1.2), beautiful and aesthetic, (otherworldly), highly insanely detailed, masterpiece, top quality, best quality, highres, 4k, 8k, RAW photo, (very aesthetic, beautiful and aesthetic), 1girl, solo, \nTower13_Gizelle, \na beautiful elvish girl, \n<lora:UnderGround-CP:1>, \nCar Parking,road,concrete,parking, \npure blue background,transparent background, \n \ndark_skin, tan_skin, tanned skin, dark skin, dark-skinned, black-skinned, bronze skin, \n(salt and pepper hair,red brown hair,), (fantasy world), (fantasy world)", ADetailer negative prompt 2nd: "(African American, African:1.6), EasyNegative, (normal quality, low quality, worst quality:1.4), jpeg artifacts, (username, watermark, signature, time signature, timestamp, artist name, artist signature, artist logo, twitter username, patreon username, copyright name, copyright notice, copyright abbreviation, copyright signature, copyright), (loli, child, infant, baby:1.3), (bad anatomy, extra digits, extra_fingers, wrong finger, inaccurate limb, bad hand, bad fingers), (African American, African:1.6), (*****, nipple, nipples:1.6), (pubic hair:1.6), multiple views, multiple frame", ADetailer confidence 2nd: 0.3, ADetailer dilate erode 2nd: 4, ADetailer mask blur 2nd: 4, ADetailer denoising strength 2nd: 0.4, ADetailer inpaint only masked 2nd: True, ADetailer inpaint padding 2nd: 32, ADetailer ControlNet model 2nd: Passthrough, ADetailer version: 24.5.1, sv_prompt: "(otherworldly), highly insanely detailed, masterpiece, top quality, best quality, highres, 4k, 8k, RAW photo, (very aesthetic, beautiful and aesthetic), 1girl, solo, \nTower13_Gizelle, \na beautiful elvish girl, \n<lora:UnderGround-CP:1>, \n__lazy-wildcards/subject/architectural/parking/prompts__, \n__lazy-wildcards/dataset/background-color__, \n#, __cf-waitress/prompt-full__, \n$char-skin-tanned-dark-黑皮-bronze-001, \n(__lazy-wildcards/char/haircolor__), (fantasy world)", sv_negative: "EasyNegative, (normal quality, low quality, worst quality:1.4), jpeg artifacts, (username, watermark, signature, time signature, timestamp, artist name, artist signature, artist logo, twitter username, patreon username, copyright name, copyright notice, copyright abbreviation, copyright signature, copyright), (loli, child, infant, baby:1.3), (bad anatomy, extra digits, extra_fingers, wrong finger, inaccurate limb, bad hand, bad fingers), (African American, African:1.6), (*****, nipple, nipples:1.6), (pubic hair:1.6), multiple views, multiple frame", Dynamic Prompts: {"use_fixed_seed": false, "unlink_seed_from_prompt": true, "enable_jinja_templates": false}, Template: "(otherworldly), highly insanely detailed, masterpiece, top quality, best quality, highres, 4k, 8k, RAW photo, (very aesthetic, beautiful and aesthetic), 1girl, solo, \nTower13_Gizelle, \na beautiful elvish girl, \n<lora:UnderGround-CP:1>, \n__lazy-wildcards/subject/architectural/parking/prompts__, \n__lazy-wildcards/dataset/background-color__, \n#, __cf-waitress/prompt-full__, \ndark_skin, tan_skin, tanned skin, dark skin, dark-skinned, black-skinned, bronze skin, \n(__lazy-wildcards/char/haircolor__), (fantasy world)", Cutoff enabled: True, Cutoff targets: ["white", "black", "green", "red", "blue", "yellow", "pink", "purple", "bronze", "*****", "silver", "magenta"], Cutoff padding: _</w>, Cutoff weight: 0.5, Cutoff disable_for_neg: True, Cutoff strong: False, Cutoff interpolation: lerp, Lora hashes: "UnderGround-CP: 840de6c452f6", Template Generated: "(otherworldly), highly insanely detailed, masterpiece, top quality, best quality, highres, 4k, 8k, RAW photo, (very aesthetic, beautiful and aesthetic), 1girl, solo, \nTower13_Gizelle, \na beautiful elvish girl, \n, \nCar Parking,road,concrete,parking, \npure blue background,transparent background, \n \ndark_skin, tan_skin, tanned skin, dark skin, dark-skinned, black-skinned, bronze skin, \n(salt and pepper hair,red brown hair,), (fantasy world)", Template Seeds: [557152046], Template Seeds Sub: [2223099060], TI hashes: "Tower13_Gizelle: 9ece223c52f8, Tower13_Gizelle: 9ece223c52f8, Tower13_Gizelle: 9ece223c52f8, Tower13_Gizelle: 9ece223c52f8, Tower13_Gizelle: 9ece223c52f8, Tower13_Gizelle: 9ece223c52f8, EasyNegative: c74b4e810b03", Hardware Info: "RTX 3060 Ti 8GB, 13th Gen i7-13700, 32GB RAM", Time taken: 26.5 sec., Version: f0.0.17v1.8.0rc-1.7.0,Template Generated Grid: ["(otherworldly), highly insanely detailed, masterpiece, top quality, best quality, highres, 4k, 8k, RAW photo, (very aesthetic, beautiful and aesthetic), 1girl, solo, \nTower13_Gizelle, \na beautiful elvish girl, \n<lora:UnderGround-CP:0>, \nCar Parking,road,concrete,parking, \npure black background,pure red background,pure cyan background , \n \ndark_skin, tan_skin, tanned skin, dark skin, dark-skinned, black-skinned, bronze skin, \n(neon orange hair,maroon hair,), (fantasy world)", "(otherworldly), highly insanely detailed, masterpiece, top quality, best quality, highres, 4k, 8k, RAW photo, (very aesthetic, beautiful and aesthetic), 1girl, solo, \nTower13_Gizelle, \na beautiful elvish girl, \n<lora:UnderGround-CP:0>, \nCar Parking,road,concrete,parking, \nsalt and pepper background, \n \ndark_skin, tan_skin, tanned skin, dark skin, dark-skinned, black-skinned, bronze skin, \n(copper hair,colored inner hair), (fantasy world)", "(otherworldly), highly insanely detailed, masterpiece, top quality, best quality, highres, 4k, 8k, RAW photo, (very aesthetic, beautiful and aesthetic), 1girl, solo, \nTower13_Gizelle, \na beautiful elvish girl, \n<lora:UnderGround-CP:0>, \nCar Parking,road,concrete,parking, \nturquoise background, \n \ndark_skin, tan_skin, tanned skin, dark skin, dark-skinned, black-skinned, bronze skin, \n(emerald green hair,sparkling silver hair,silver hair,rainbow hair,Iridescence hair,multi_color_hair,multicolored hair,multi colored hair), (fantasy world)"]
'''

res = {}

# 增加解析和处理数组和对象的逻辑
for k, v in re_param.findall(lastline):
    try:
        if v.startswith('"') and v.endswith('"'):
            v = unquote(v)
        elif v.startswith('[') and v.endswith(']'):
            v = json.loads(v)
        elif v.startswith('{') and v.endswith('}'):
            v = json.loads(v)
        else:
            m = re_imagesize.match(v)
            if m:
                res[f"{k}-1"] = m.group(1)
                res[f"{k}-2"] = m.group(2)
                continue
            v = v.strip()  # Remove surrounding spaces for non-JSON values

        res[k] = v
    except Exception as e:
        print(f"Error parsing \"{k}: {v}\": {e}")

print(json.dumps(res, indent=2))
 
by

Python Online Compiler

Write, Run & Share Python code online using OneCompiler's Python online compiler for free. It's one of the robust, feature-rich online compilers for python language, supporting both the versions which are Python 3 and Python 2.7. Getting started with the OneCompiler's Python editor is easy and fast. The editor shows sample boilerplate code when you choose language as Python or Python2 and start coding.

Taking inputs (stdin)

OneCompiler's python online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample python program which takes name as input and print your name with hello.

import sys
name = sys.stdin.readline()
print("Hello "+ name)

About Python

Python is a very popular general-purpose programming language which was created by Guido van Rossum, and released in 1991. It is very popular for web development and you can build almost anything like mobile apps, web apps, tools, data analytics, machine learning etc. It is designed to be simple and easy like english language. It's is highly productive and efficient making it a very popular language.

Tutorial & Syntax help

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition IF-ELSE is used.

if conditional-expression
    #code
elif conditional-expression
    #code
else:
    #code

Note:

Indentation is very important in Python, make sure the indentation is followed correctly

2. For:

For loop is used to iterate over arrays(list, tuple, set, dictionary) or strings.

Example:

mylist=("Iphone","Pixel","Samsung")
for i in mylist:
    print(i)

3. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while condition  
    #code 

Collections

There are four types of collections in Python.

1. List:

List is a collection which is ordered and can be changed. Lists are specified in square brackets.

Example:

mylist=["iPhone","Pixel","Samsung"]
print(mylist)

2. Tuple:

Tuple is a collection which is ordered and can not be changed. Tuples are specified in round brackets.

Example:

myTuple=("iPhone","Pixel","Samsung")
print(myTuple)

Below throws an error if you assign another value to tuple again.

myTuple=("iPhone","Pixel","Samsung")
print(myTuple)
myTuple[1]="onePlus"
print(myTuple)

3. Set:

Set is a collection which is unordered and unindexed. Sets are specified in curly brackets.

Example:

myset{"iPhone","Pixel","Samsung"}
print{myset}

4. Dictionary:

Dictionary is a collection of key value pairs which is unordered, can be changed, and indexed. They are written in curly brackets with key - value pairs.

Example:

mydict = {
    "brand" :"iPhone",
    "model": "iPhone 11"
}
print(mydict)

Supported Libraries

Following are the libraries supported by OneCompiler's Python compiler

NameDescription
NumPyNumPy python library helps users to work on arrays with ease
SciPySciPy is a scientific computation library which depends on NumPy for convenient and fast N-dimensional array manipulation
SKLearn/Scikit-learnScikit-learn or Scikit-learn is the most useful library for machine learning in Python
PandasPandas is the most efficient Python library for data manipulation and analysis
MatplotlibMatplotlib is a cross-platform, data visualization and graphical plotting library for Python programming and it's numerical mathematics extension NumPy
DOcplexDOcplex is IBM Decision Optimization CPLEX Modeling for Python, is a library composed of Mathematical Programming Modeling and Constraint Programming Modeling