Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I print items from a tuple?

I got the tuple -

Result = [
    ('80407', 'about power supply of opertional amplifier', '11 hours ago'),
    ('80405', '5V Regulator Power Dissipation', '11 hours ago')]

I want to iterate over the tuples and separate the items in the tuples by ;.

The output should be as follows -

80407;about power supply of opertional amplifier;11 hours ago

I tried the following:

for item in zip(*Result):
    print(*item[0], end=';')

Which gave me the result -

8 0 4 0 7;a b o u t   p o w e r   s u p p l y   o f   o p e r t i o n a l   a m p l i f i e r;1 1   h o u r s   a g o;

and

for item in Result:
    print(*item[0], end=';')

Which gave me -

8 0 4 0 7;8 0 4 0 5;

How to properly iterate over a tuple?

like image 766
Alex_P Avatar asked Dec 11 '22 02:12

Alex_P


1 Answers

Join the items in the tuple with a ;, and join the resultant string in the outer list with another separator, perhaps a newline \n

s = '\n'.join(';'.join(lst) for lst in Result)
print(s)

The output will be

80407;about power supply of opertional amplifier;11 hours ago
80405;5V Regulator Power Dissipation;11 hours ago
like image 88
Devesh Kumar Singh Avatar answered Jan 01 '23 21:01

Devesh Kumar Singh