如何从列表中删除从开始到结束的范围
发布时间:2020-12-20 11:18:48 所属栏目:Python 来源:网络整理
导读:def remove_section(alist,start,end): """ Return a copy of alist removing the section from start to end inclusive inlist = [8,7,6,5,4,3,2,1] remove_section(inlist,5) [8,1] inlist == [8,1] True inlist = ["bob","sue","jim","mary","tony"] remo
def remove_section(alist,start,end): """ Return a copy of alist removing the section from start to end inclusive >>> inlist = [8,7,6,5,4,3,2,1] >>> remove_section(inlist,5) [8,1] >>> inlist == [8,1] True >>> inlist = ["bob","sue","jim","mary","tony"] >>> remove_section(inlist,1) ['jim','mary','tony'] >>> inlist == ["bob","tony"] True """ 我有点难过如何去做这个任何帮助将非常感激. 解决方法
这应该做你想要的:
def remove_section(alist,end): return alist[:start] + alist[end+1:] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |