I have a string, containing a range of numbers. I need to know how many elements are in the range. The tricky part is that it could be a combination of hyphen separated range of numbers, or individual comma-delimited numbers. Some examples, with the expected count:

> 
> 
> ```
> "1-10,12,14,16" : 13  
> "8,14,0-5" : 8  
> "0-32" : 33  
> "1-5,10-15" : 11
> 
> ```
> 
> 

There won't be any overlapping in the values given, so I don't have to account for that. (ie, you won't see "1-10,5,6", for example)

This seems like something Python should be able to do easily, but I don't know how to do it in a pythonic way. How can I accomplish this task?

What I currently have:

```
count = 0
range = "1,2,3-4"
for a_range in ranges:
    if "-" in a_range:
        first,last = a_range.split("-")
        amt = int(last) - int(first) +1
    else:
        amt = 1
    count += amt
print(count)

```