RonB7
RonB7

Reputation: 297

List within a string and print formatting

I am creating something which takes a tuple, converts it into a string and then reorganises the string using print formatting. 'other' can sometimes have 2 names, hence why I have used * and the " ".join(other) in this function:

def strFormat(x):

    #Convert to string
    s=' '
    s = s.join(x)
    print(s)

    #Split string into different parts
    payR, dep, sal, *other, surn = s.split()
    payR, dep, sal, " ".join(other), surn

    #Print formatting!
    print (surn , other, payR, dep, sal) 

The problem with this is that it prints a list of 'other' within the string like this:

Jones ['David', 'Peter'] 84921 Python 63120

But I want it more like this:

Jones David Peter 84921 Python 63120

So that it is ready for formatting into something like this:

Jones, David Peter      84921 Python      £63120

Am I going about this the right way and how do I stop the list appearing within the string?

Upvotes: 0

Views: 66

Answers (1)

Aran-Fey
Aran-Fey

Reputation: 43326

You're close. Change this line (which does nothing):

payR, dep, sal, " ".join(other), surn

to

other = " ".join(other)

Upvotes: 3

Related Questions