Question: everyone! I'm using matplotlib and I have a field with randomly generated circles. Also I have button which has to generate new random circles in the field but every time I press it, circles are generated inside the BUTTON, but not in the field. Please show me what I'm doing wrong, I'm new to python(actually started learning it yesterday). Here is my code: 

```
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Button

plt.subplots_adjust(bottom=0.2)

N = 10
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
area = np.pi * 0.2
l = plt.scatter(x, y, s=area, c=colors, alpha=0.8)

def gen(event):
    N = 10
    x = np.random.rand(N)
    y = np.random.rand(N)
    colors = np.random.rand(N)
    area = np.pi * 0.2
    plt.scatter(x, y, s=area, c=colors, alpha=0.8)
    plt.draw()

axgen = plt.axes([0.81, 0.05, 0.1, 0.075])
bgen = Button(axgen, 'Generate')
bgen.on_clicked(gen)

plt.show()

```

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

Answer: 
What you have is efficient enough, really. In this context almost anything you could dream up is efficient enough, but for neatness? Well, I would've at least refactored the conversion into a function, and do you really need a long int to store the age levels? I doubt it as humans generally don't become *that* old. I would just go for a regular int.

Something like this:

```
int ConvertFromMaturityConfig(string maturityConfig)
{
    string ageString = maturityConfig.Split('=')[0];
    return int.Parse(ageString);
}

```

Usage:

```
string maturity = "0=Child|13=Teen|18=Adult";
string[] configuration = maturity.Split('|');

int childAgeMin = ConvertFromMaturityConfig(configuration[0]);
int teenAgeMin = ConvertFromMaturityConfig(configuration[1]);
int adultAgeMin = ConvertFromMaturityConfig(configuration[2]);

```

I would also consider trying to determine which configuration belongs to which value. As it is, you're expecting you get the child age, the teen age and the adult age, in that order. Personally, with the constraints you have, I would've put it into a dictionary so that you could look it up there. Then you could have something like this:

```
string maturity = "0=Child|13=Teen|18=Adult";
var config = maturity.Split('|')
    .Select(s => s.Split('='))
    .ToDictionary(
        c => c[1], // key selector
        c => int.Parse(c[0]));

```

Then you can use it like this:

```
if (age >= config["Child"] && age < config["Teen"])
    maturity = "Child";
else if (age >= config["Teen"] && age < config["Adult"])
    maturity = "Teen";
else if (age >= config["Adult"]) 
    maturity = "Adult";

```

You would be wise to consider what happens if the age is below the minimum child age, by the way.
try this

```
string str = "0=Child|13=Teen|18=Adult";
            List<string> seplist = str.Split('|').ToList();
            int Age = 14;
            string Maturity = string.Empty;
            foreach (var item in seplist)
            {
                var part = item.Split('=');
                if (int.Parse(part.First()) <= Age)
                    Maturity = part.Last();
                else
                {
                    if (int.Parse(part.First()) > Age)
                        break;
                }
            }
            Console.WriteLine(Maturity);
            Console.ReadLine();

```