G
gervaz
Hi all, I would like to ask you how I can use the more efficient join
operation in a code like this:
.... def __init__(self, v1, v2):
.... self.v1 = v1
.... self.v2 = v2
........ txt = ""
.... for x in l:
.... if x.v1 is not None:
.... txt += x.v1 + "\n"
.... if x.v2 is not None:
.... txt += x.v2 + "\n"
.... return txt
....
The idea would be create a new list with the values not None and then
use the join function... but I don't know if it is really worth it.
Any hint?
.... e = []
.... for x in l:
.... if x.v1 is not None:
.... e.append(x.v1)
.... if x.v2 is not None:
.... e.append(x.v2)
.... return "\n".join(e)
....'hello\nciao\nsalut\nhallo'
Thanks, Mattia
operation in a code like this:
.... def __init__(self, v1, v2):
.... self.v1 = v1
.... self.v2 = v2
........ txt = ""
.... for x in l:
.... if x.v1 is not None:
.... txt += x.v1 + "\n"
.... if x.v2 is not None:
.... txt += x.v2 + "\n"
.... return txt
....
'hello\nciao\nsalut\nhallo\n't1 = Test("hello", None)
t2 = Test(None, "ciao")
t3 = Test("salut", "hallo")
t = [t1, t2, t3]
prg(t)
The idea would be create a new list with the values not None and then
use the join function... but I don't know if it is really worth it.
Any hint?
.... e = []
.... for x in l:
.... if x.v1 is not None:
.... e.append(x.v1)
.... if x.v2 is not None:
.... e.append(x.v2)
.... return "\n".join(e)
....'hello\nciao\nsalut\nhallo'
Thanks, Mattia