Question: I'm trying to set my progressbar from another class but failed. This is my progressbar the class `Upload`.

```
JProgressBar progressBar = new JProgressBar();
progressBar.setBounds(91, 134, 284, 17);
frame.getContentPane().add(progressBar);

```

I have another class called `Read`. In this class I have a loop that needs to read a file, so I want to set the progress with the iterator `i` from that class. I know that I have to set the minimum and maxium like this:

```
progressBar.setMinimum(0);
progressBar.setMaximum(numRows);

```

And for the value:

```
progressBar.setValue(newValue);

```

How can I set the value for the progressbar so it keeps updating the value of `i`?

Answer: 
Use [`next()`](https://docs.python.org/2/library/functions.html#next) and [`enumerate()`](https://docs.python.org/2/library/functions.html#enumerate) to find the position of the string with the desired date, then *slice*:

```
>>> d = '20150407'
>>> l = [
...     '20150406,34.4800,34.8100,34.2300,34.4200,21480500',
...     '20160402,34.1,32.8100,33.2300,31.01,22282510',
...     '20150407,34.5400,34.8900,34.5100,34.6300,14331200',
...     '20120101,2.540,14.8201,32.00,30.1311,12331230'
... ]
>>> index = next(i for i, item in enumerate(l) if item.startswith(d))
>>> l[:index]
['20150406,34.4800,34.8100,34.2300,34.4200,21480500', '20160402,34.1,32.8100,33.2300,31.01,22282510']
>>> l[index:]
['20150407,34.5400,34.8900,34.5100,34.6300,14331200', '20120101,2.540,14.8201,32.00,30.1311,12331230']

```

Couple notes:

* `next()` would through a `StopIteration` exception if there will be no match - you should either handle it with `try/except` or provide a default value, `-1` for example:

```
next((i for i, item in enumerate(l) if item.startswith(d)), -1)

```
* to check if the date matches a desired one, we are simply checking if an item starts with a specific date string. If the desired date comes as a `date` or `datetime`, you would need to format it beforehand using `strftime()`:

```
>>> from datetime import datetime
>>> d = datetime(2015, 4, 7)
>>> d = d.strftime("%Y%m%d")
>>> d
'20150407'

```
by extend from alecxe answer:
The code can split original list to couple sublist by input date.

```
l = [
...      '20150406,34.4800,34.8100,34.2300,34.4200,21480500',
...      '20160402,34.1,32.8100,33.2300,31.01,22282510',
...      '20150407,34.5400,34.8900,34.5100,34.6300,14331200',
...      '20120101,2.540,14.8201,32.00,30.1311,12331230',
...  '20150407,34.5400,34.8900,34.5100,34.6300,14331200',]

index = [i for i, item in enumerate(l) if item.startswith(d)]
[l[i:j] for i, j in zip([0]+index, index+[None])]

output:
[['20150406,34.4800,34.8100,34.2300,34.4200,21480500', '20160402,34.1,32.8100,33.2300,31.01,22282510'], ['20150407,34.5400,34.8900,34.5100,34.6300,14331200', '20120101,2.540,14.8201,32.00,30.1311,12331230'], ['20150407,34.5400,34.8900,34.5100,34.6300,14331200']]

```