What are you using to produce your list? Both getResources and pdoResources have &tplOdd properties. They also have &tplFirst and &tplLast properties.
It’s generally not a good practice to have separate
conditional statements that produce opening and closing tags and that depend on the number of data items you’re processing.
One way to go would be to have &tplFirst, &tplLast, and &tplOdd chunks that are identical except for the classes in the div tags they contain. That way you can use CSS to add different top and bottom margins that will space each div the way you want it to look regardless of how many there are.
With getResources, there is a placeholder [[+last]] available, that contains the index of the last row. There exists also a placeholder [[+odd]].
To combine the two placeholders you probably have to write a custom snippet.