Question: ```
class SpreadsheetRow(object):
def __init__(self,Account1):
    self.Account1=Account1
    self.Account2=0

```

I have a while loop that fills a list of objects ,and another loop that fills a dictionary associating Var1:Account2. But, I need to get that dictionary's value into each object, if the key matches the object's Account1.

So basically, I have:

```
listofSpreadsheetRowObjects=[SpreadsheetRow1, SpreadsheetRow2, SpreadsheetRow3]
dict_var1_to_account2={1234:888, 1991:646, 90802:5443}

```

I've tried this:

```
for k, v in dict_var1_to_account2.iteritems():
    if k in listOfSpreadsheetRowObjects:
        if self.account1=k:
              self.account2=v

```

But, it's not working, and I suspect it's my first "if" statement, because listOfSpreadsheetRowObjects is just a list of those objects. How would I access account1 of each object, so I can match them as needed? 

Eventually, I should have three objects with the following information:
SpreadsheetRow
self.Account1=Account1
self.Account2=(v from my dictionary, if account1 matches the key in my dictionary)

Answer: 
In most cases the point of having classes and subclasses is that we can cast them as a base class (or interface) and no longer have to distinguish between specific types. 

If you sort these in a way that is aware of the type and you have five or six types then you're eventually going to end up with this:

```
.OrderBy(o => o is SingleYear)
    .ThenBy(o => o is Period)
    .ThenBy(o => o is SomeOtherClass)
    .ThenBy(o => o is Another)
    .ThenBy(o => o is Whatever)
    .ThenBy(o => o is Etc)
    .ThenBy(o => o.Time);

```

It's not the end of the world but I wouldn't like it. It's better if we don't differentiate between classes in our code (inspecting to see what type they are.) Instead, classes differentiate *themselves* by implementing properties and methods differently.

Does the sort order depend on the length of the period? You could have your classes implement a property that indicates the length of a period - perhaps that's constant for `SingleYear` but calculated for `Period`. 

Then you could either implement `IComparable` on each class or provide a separate `IComparer<T>` implementation, like

```
public class TimeComparer : IComparer<Time>
{
    public int Compare(Time t1, Time t2)
    {
        var periodComparison = t1.Duration.CompareTo(t2.Duration);
        return periodComparison != 0 ? periodComparison : t1.Time.CompareTo(t2.Time);
    }
}

```
I think this would do it:

```
list.OrderBy(t => typeof(t).Name).ThenBy(o => o.Time)

```