Given a list of values remove first occurrence

前端 未结 3 1913
旧巷少年郎
旧巷少年郎 2021-01-19 03:39
def drop dest(routes,location):
    for i in range(len(routes)):
        if routes[i] == location:
              routes.remove(routes[i])
    return routes
         


        
3条回答
  •  旧巷少年郎
    2021-01-19 04:18

    It's simple, use list.remove.

    >>> routes = [(3,2),(2,4),(5,5),(2,4)]
    >>> routes.remove((2,4))
    >>> routes
    [(3, 2), (5, 5), (2, 4)]
    

提交回复
热议问题