Question: ```
d={'Bat':1,'Tennisball':3,'Racquet':2,'Shuttlecock':3,'Javelin':1,'Soccer':1,'Hockey':7,'Gloves':8}

```

I want the last value of dictionary not key

Answer: 
The most efficient way, in *O(1)*, is to use [`dict.popitem`](https://docs.python.org/3/library/stdtypes.html#dict.popitem):

```
k, last_value = _, d[k] = d.popitem()

```

LIFO order is guaranteed since Python 3.7 (the same version when dictionary insertion ordering was guaranteed).

If the double assignment seems too tricky, consider

```
last_value = d[next(reversed(d))]

```

Here are the timing comparisons (CPython 3.10 on linux):

```
>>> d={'Bat':1,'Tennisball':3,'Racquet':2,'Shuttlecock':3,'Javelin':1,'Soccer':1,'Hockey':7,'Gloves':8}
>>> timeit k, last_value = _, d[k] = d.popitem()
107 ns ± 3.34 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
>>> timeit next(reversed(d.values()))
150 ns ± 0.237 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
>>> timeit d[next(reversed(d))]
134 ns ± 0.503 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

```
Python docs (v3.7+) say:

> 
> Performing list(d) on a dictionary returns a list of all the keys used
> in the dictionary, in insertion order (if you want it sorted, just use
> sorted(d) instead). To check whether a single key is in the
> dictionary, use the in keyword.
> 
> 
> 

Therefore `list(d)[-1]` results in final *key*, `d[list(d)[-1]]` will return final value.

Prior to python 3.7, dictionaries were unordered.