I attempted to do the problem 1313. Decompress Run-Length Encoded List on Leetcode, my code runs perfectly on my IDE, however when I submit it on Leetcode, sometimes, the dictionary is iterated backwards, causing my output list to be in reverse order. I'm 95% certain that my code is correct because it passed 3-4 test cases before the dictionary is iterated backwards on the same test case. Is this a bug, or is there something wrong with my code? Thanks for you help!
class Solution(object):
def decompressRLElist(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
d = {}
l = []
for i in range(0, len(nums), 2):
d[nums[i+1]] = nums[i]
print(d)
for (k,v) in d.items():
for j in range(v):
l.append(k)
return l