Using map() function with keyword arguments

前端 未结 5 1187
心在旅途
心在旅途 2020-11-28 06:29

Here is the loop I am trying to use the map function on:

volume_ids = [1,2,3,4,5]
ip = \'172.12.13.122\'
for volume_id in volume_ids:
    my_fun         


        
5条回答
  •  [愿得一人]
    2020-11-28 07:21

    How about this?

    results = []
    for volume_id in volume_ids:
        results.append(my_function(volume_id, ip=ip))
    

    This is three lines of code instead of one --- it's three lines of clear and obvious code instead of importing some special-case helper from module such-and-such. This argument is probably a matter of taste, but it has a lot of weight depending on who you talk to.

提交回复
热议问题