Hi HOWARD WILLIAMS ,
The line you refer to is using "List comprehensions". To learn more about them I recommend List comprehensions... posted by Dan Patterson.
In short, let's start a line before:
years = [str(year) for year in range(1999, 2014)]
This will generate a list called "years" with the following content:
['1999', '2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013']
This list "years" is used in the List comprehension:
range_years = ['{0}_{1}'.format(years[0], year) for year in years[1:]]
The result of this line is a list called "range_years" with this content:
['1999_2000', '1999_2001', '1999_2002', '1999_2003', '1999_2004', '1999_2005', '1999_2006', '1999_2007', '1999_2008', '1999_2009', '1999_2010', '1999_2011', '1999_2012', '1999_2013']
Let's take the line apart. We don't use the entire list of year but start at index 1 (the second element of the list)
print years[1:]
... returns:
['2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013']
For each year in this part of the list (2000 until 2013) we use a string and a format command.
Example:
print '{0}_{1}'.format('hello', 'there')
Will return:
hello_there
So we have a string '{0}_{1}' and the string has a method called 'format' that allows us to pass two parameters 'hello' and 'there' and it will be formatted to 'hello_there'. {0} will be replaced by the first parameter and {1} by the second.
This is also done with the parameters years[0] and year. The first (years[0]) takes the first element of the list years (in this case '1999') and the second is the one that changes in the loop (varies from '2000' to '2013'). This creates the list of the year ranges we need in the process.