[Python] combine two strings in python

Discussão em 'Python' iniciado por Stack, Junho 20, 2025.

  1. Stack

    Stack Membro Participativo

    I have a list1 like this,

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


    I want to get a new list2 like this (joining first element with second element's second entry);

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


    As a first step, I am checking to join the first two elements in the tuple as follow,

    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


    I was expecting this;

    my2
    name8


    what I am doing wrong? Is there any good way to do this? a simple way..

    Continue reading...

Compartilhe esta Página