Replacing characters of string in a list
<p>I am replacing the character and/or string in l3 by comparing it with l1 and l2 . What output I am getting and what output I like to get is shown below.</p>

<p>my code </p>

<pre><code>l1 = ["Jai","Sharath","Ravi","Aditya"]
l2 = ["Singh","Kumar","Sharma","Rao"]
l3 = ["J.Singh","Sharath_K","R-Sharma","Rao_Aditya"]
for x,y,z in zip(l1,l2,l3):
  if x in z:
    z.replace(x,"Firstname")
  elif x[0] in z:
    z.replace(x[0],"First/Character/of/first/name")
  elif y in z:
    z.replace(y,"lastname")
  else:
    z.replace(y[0],"First/Character/of/last/name")
</code></pre>

<p>my output</p>

<pre><code>'First/Character/of/first/name.Singh'
'Firstname_K'
'First/Character/of/first/name/Sharma'
'Rao_Firstname'
</code></pre>

<p>my expected output</p>

<pre><code>'First/Character/of/first/name.lastname'
'Firstname_First/Character/of/last/name'
'First/Character/of/first/name/lastname'
'lastname_Firstname'
</code></pre>

<p>how do i get my desired output?</p>

<p>Strings are immutable. <code>replace</code> does not work in-place, it returns a new string. You need to reallocate that new string to the original name.</p>

<pre><code>if x in z:
    z = z.replace(x,"Firstname")
</code></pre>

<p>(Also, please use more than one space indentation.)</p>

python python-3.x