Python合并两个列表中的项目 [英] Python merge items from two list

查看:201
本文介绍了Python合并两个列表中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

    for j in range(4):
      print md_array[j:j+1]
    for j in range(4):  
      print y_array[j:j+1]
    for j in range(4):
      print md_array[j:j+1]+y_array[j:j+1]
    for j in range(4):
      print "%s%s" % (md_array[j:j+1], y_array[j:j+1])

结果是:

['12/1/']['12/2/']['12/3/']['12/34/']
['2011']['2010']['2009']['2008']
['12/1/', '2011']['12/2/', '2010']['12/3/', '2009']['12/34/', '2008']
['12/1/']['2011']['12/2/']['2010']['12/3/']['2009']['12/34/']['2008']

实际上我想输出

    ['12/1/2011']['12/2/2010']['12/3/2009']['12/34/2008']

我尝试追加,但失败了...所以我的代码出了什么问题?

I tried append but failed...So what's wrong with my codes??

推荐答案

print "".join("[%s%s]"%t for t in zip(md_array, y_array))

这篇关于Python合并两个列表中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆