Skip to content

Commit

Permalink
pop outside iterator
Browse files Browse the repository at this point in the history
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
  • Loading branch information
jayzhan211 committed May 18, 2024
1 parent 80afb8a commit 6846af8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions stdlib/src/collections/dict.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,17 @@ struct Dict[K: KeyElement, V: CollectionElement](
"KeyError" if the dictionary is empty.
"""

var key = Optional[K](None)
var val = Optional[V](None)

for item in reversed(self.items()):
var key = item[].key
var value = item[].value
_ = self.pop(key)
return DictEntry[K, V](key, value)
key = Optional(item[].key)
val = Optional(item[].value)
break

if key:
_ = self.pop(key.value()[])
return DictEntry[K, V](key.value()[], val.value()[])

raise "KeyError"

Expand Down

0 comments on commit 6846af8

Please sign in to comment.