小编Luc*_*hns的帖子

Popping items from a list using a loop

I am trying to write a for loop in python to pop out all the items in a list but two, so I tried this:

guest = ['john', 'phil', 'andy', 'mark', 'frank', 'joe']

for people in guest:
  popped_guest = guest.pop()
  print("I am sorry " + popped_guest + " I can no longer invite you to dinner")
Run Code Online (Sandbox Code Playgroud)

and this is what I get when I run it:

I am sorry joe I can no longer invite you to dinner

I am …

python for-loop python-3.x

4
推荐指数
2
解决办法
1662
查看次数

标签 统计

for-loop ×1

python ×1

python-3.x ×1