Reputation: 21
I'm very new to python and I am wanting to simply find out the number of values in a list between two latitudes.
I thought a simple if statement would suffice, but apparently not. My coding looks like this:
if lat < 62 & lat > 58:
z = len(lat)
print z
I then want to be able to get rid of repeated numbers. So how would I do that?
Upvotes: 1
Views: 60
Reputation: 53678
&
is a bitwise AND operator. You should instead use and
.
Alternatively you can use chained operators as shown below:
if 58 < lat < 62:
# do whatever you need to...
What you're actually trying to do is calculate how many of your latitudes are within the range (58, 62). In that case you can do z = sum(58 < i < 62 for i in lat)
. This makes use of the fact that in Python True
is equal to 1 and False
is equal to 0. So if an element is within the range then it'll count as 1 and when you sum them all then only True (1) values will count up.
Upvotes: 2