Python如何打印列表列表

Sac*_*n S 1 python python-3.x

我想用下面的代码打印python 3.x中的列表列表,但是它给出了一个错误.

lol=[[1,2],[3,4],[5,6],['five','six']]
for elem in lol:
      print (":".join(elem))
# this is the error I am getting-> TypeError: sequence item 0: expected str instance, int found
Run Code Online (Sandbox Code Playgroud)

我期待这个输出:

1:2
3:4
5:6
five:six
Run Code Online (Sandbox Code Playgroud)

我可以使用下面的perl代码实现相同的输出(这仅供参考):

for (my $i=0;$i<scalar(@{$lol});$i++)
{
    print join(":",@{$lol->[$i]})."\n";
}
Run Code Online (Sandbox Code Playgroud)

我怎么在python 3.x中做到这一点?

Jon*_*nts 7

我会去:

for items in your_list:
    print (*items, sep=':')
Run Code Online (Sandbox Code Playgroud)

这利用了print作为一个函数,不需要连接或显式字符串转换.