Question: I am trying to use a dictionary to divide its elements in order to get a value. If that value is in my criteria I wish to stop. I have managed to make it work, but I feel there must be a shorter way. If you have any suggestions or advice I would appreciate it.

```
dict1 = {1:123, 2:220, 3:290, 4:300, 5:329} 
prev = 1 
prev_key = 1 
for key,value in dict1.items():
    z = prev/value
    if z >= 0.95 and z<= 1.05:
        print("key is",prev_key)
        break
    prev = value
    prev_key = key

```

In this scenario the answer is prev\_key = 3. Thanks in advance :)

Answer: 
```
require(rtidy)
require(ggplot2)

result %>% 
  add_rownames("model") %>% 
  gather("Activity","value",-model) %>% 
  ggplot(aes(x=Activity,y=value,color=model,group=model)) + geom_line()

```

[![enter image description here](https://i.stack.imgur.com/6r1Ci.png)](https://i.stack.imgur.com/6r1Ci.png)
You could transpose the data and use `pivot_longer` to create rows for each model.  

Try:

```
library(tidyverse)
data <- t(result) %>% as.data.frame %>% 
                      rownames_to_column() %>%
                      pivot_longer(cols = rownames(result),names_to = "model")

ggplot(data) + geom_line(aes(group = model, x=rowname,y=value,color=model)) + xlab('Exercice')

```

[![enter image description here](https://i.stack.imgur.com/AkpSJ.png)](https://i.stack.imgur.com/AkpSJ.png)