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>Consider your use of <code>elif</code>.  If your first condition triggers, replacing the first name, will the last condition trigger to replace the last name?  You may want to try two <code>if</code> <code>else</code> structures.  </p>

<p>Consider the following:</p>

<pre><code>z = 'abc'
if z[0] == 'a':
    z = z.replace('a', '1')
elif z[1] == 'b':
    z = z.replace('b', '2')
if z[2] == 'c':
    z = z.replace('c', '3')
</code></pre>

<p>What will z be at the end of this block?  Would removing the <code>z =</code> change that?  How does changing the conditionals (<code>if</code> <code>elif</code> <code>else</code>) change the output?</p>

python python-3.x