从五个项目列表中打印除第四个项目之外的所有项目,两个列表彼此相邻

Adi*_*ous 0 python python-2.7

所以我遇到的这个新问题就是这个问题.我有两个列表,每个列表有五个项目.

listone = ['water', 'wind', 'earth', 'fire', 'ice']
listtwo = ['one', 'two', 'three', 'four', 'five']
Run Code Online (Sandbox Code Playgroud)

我想要做的是从字符串中的每个列表中打印第一,第二,第三和第五项:

print("the number is %s the element is %s" % (listtwo, listone)
Run Code Online (Sandbox Code Playgroud)

但是他们每次都需要在一个新行中打印,以便为两个列表中的每个元素运行文本:

the number is one the element is water
the number is two the element is wind
the number is three the element is earth
the number is five the element is five
Run Code Online (Sandbox Code Playgroud)

我不知道该怎么做.我尝试使用列表拆分,但由于它是五个中的第四个项目,我无法弄清楚如何跳过它.我还使用它来列出新行中的字符串:

for x in listone and listtwo:
print("the number is {0} the element is {0}".format(x)  
Run Code Online (Sandbox Code Playgroud)

但我不知道如何在两个列表中使用它,或者它是否可以与两个列表一起使用.

请帮忙 :(

编辑:

另外我不知道脚本的元素是什么,所以我只能在列表中使用它们的编号.所以我需要在两个列表中摆脱[4].

Pie*_* GM 7

for (i, (x1, x2)) in enumerate(zip(listone,listtwo)):
    if i != 3:
        print "The number is {0} the element is {1}".format(x1, x2)
Run Code Online (Sandbox Code Playgroud)

说明

  • zip(listone,listtwo)为您提供了一个元组列表(listone[0],listtwo[0]), (listone[1],listtwo[1])...
  • enumerate(listone) 为您提供了一个元组列表(0, listone[0]), (1, listone[1]), ...]

    (你猜对了,这是另一种更有效的方法 zip(range(len(listone)),listone)

  • 通过组合这两者,您可以获得所需元素的列表
  • 因为您的第一个元素具有索引0并且您不想要第四个元素,所以只需检查索引是否存在3