Replace text in python

Hi everyone!
i am studying python, i want to replace none value by “0”, but the output is not same input structure
please help me!
thank!

@Huynh ,

just a sidestep codeblock is doing also this job

grafik

KR

Andreas

1 Like

Hello
here is

lst=IN[0]
container_principal=[]
container_secondary=[]
for i in lst:
    for j in i:
        if j=="":
            res="0"
        else:
            res=j
        container_secondary.append(res)
    container_principal.append(container_secondary)
    container_secondary=[]
OUT = container_principal

Cordially
christian.stan

1 Like
OUT = [[element if element != "" else "0" for element in sublist] for sublist in IN[0]]

that gave me chatGPT ! :wink:

2 Likes

You give me the same in list comprehension
it’s a joke ( :wink:)

lst=IN[0]
container_principal=[]
container_secondary=[]
for i in lst:
    if isinstance(i,list):
        for j in i:
            if j=="":
                res="0"
            else:
                res=j
            container_secondary.append(res)
        container_principal.append(container_secondary)
        container_secondary=[]
    else:
        if i=="":
            res="0"
        else:
            res=i
        container_principal.append(res)
OUT = container_principal

cordially
christian.stan

Thank you, Draxl_Andreas

1 Like

Thank you christian.stan, it works

1 Like