Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (12.7k points)

Consider the below list 1,

list1 = [('my', '1.2.3', 2),('name', '9.8.7', 3)]

I also need to get a new list2 like below,

list2 = [('my2', 2),('name8', 3)]

In the first step, I'm attempting to combine the first two elements inside a tuple,

for i,j,k in list1:

    #print(i,j,k)

    x = j.split('.')[1]

    y = str(i).join(x)

    print(y)

But I get this,

2

8

But, What I expect

my2

name8

I don't know, where I went wrong?

1 Answer

0 votes
by (26.4k points)

You can try,

y=str(i)+str(x)

It will work

Join the python online course fast, to learn python concepts in detail and get certified.

For more details, do check out the below video tutorial...

Browse Categories

...