Python:如何从列表中获取第n个元素,其中n来自列表

cjg*_*123 0 python list python-2.7

所以说我有:

a = ['the dog', 'cat', 'the frog went', '3452', 'empty', 'animal']
b = [0, 2, 4]
Run Code Online (Sandbox Code Playgroud)

我怎么能回来:

c = ['the dog', 'the frog went', 'empty'] ?
Run Code Online (Sandbox Code Playgroud)

即如何从a中返回第n个元素,其中n包含在单独的列表中?

Ale*_*hez 5

使用列表理解,只需:

c = [a[x] for x in b]
Run Code Online (Sandbox Code Playgroud)