荣誉版主
- 积分
- 34026
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2013-9-12
- 最后登录
- 1970-1-1
|
本帖最后由 sanguine 于 2014-5-2 20:53 编辑
白云Amanda 发表于 2014-5-2 12:43 ![]()
大家都是交作业的,我有个问题不知道发在这里对不对。
看了第一部分视频之后,Scott有个视频里面要求删除列 ...
我的实现,仅供参考- # return the last odd number
- # be notice that there are more than one same number in the list
- def remove_last_odd(numbers):
- has_odd = False
- last_odd = 0
- count = 0
- for num in numbers:
- count += 1
- if num % 2 == 1:
- has_odd = True
- last_odd = count
- if has_odd:
- del numbers[last_odd - 1]
- # return is [1, 7, 2, 34, 8, 7, 2, 5, 14, 22, 93, 48, 76, 15]
- def run():
- numbers = [1, 7, 2, 34, 8, 7, 2, 5, 14, 22, 93, 48, 76, 15, 7]
- print numbers
- remove_last_odd(numbers)
- print numbers
- run()
复制代码 |
|