TypeError: 'dict_keys' object does not support indexing

后端 未结 5 1417
Happy的楠姐
Happy的楠姐 2020-11-27 13:21
def shuffle(self, x, random=None, int=int):
    \"\"\"x, random=random.random -> shuffle list x in place; return None.

    Optional arg random is a 0-argument fu         


        
5条回答
  •  猫巷女王i
    2020-11-27 14:12

    Convert an iterable to a list may have a cost. Instead, to get the the first item, you can use:

    next(iter(keys))
    

    Or, if you want to iterate over all items, you can use:

    items = iter(keys)
    while True:
        try:
            item = next(items)
        except StopIteration as e:
            pass # finish
    

提交回复
热议问题