I have a dictionary as shown in the picture and I'm wondering how should I code something in to check for each value for each key and check them to see if they meet a certain condition like a value above 8 and such.
http://i.imgur.com/qtfkK61.png
The values are float and there are multiple values per a dictionary value of region.
def main(): #defining main function
magList = [] #magnitude list of all together
regionList = [] #creating list to hold region names
wholeList = []
combinedList = []
with open("earthquakes.txt", "r") as eqList: #opens earthquake text file and gets the magnitudes
eqList.readline()
for line in eqList:
line = line.split()
magList.append(float(line[1])) #appends magnitude as float values in list
with open("earthquakes.txt", "r") as eqList2: #open file 2nd time for gathering the region name only
eqList2.readline()
for line in eqList2:
line = line.split()
line = line[0:7] + [" ".join(line[7:])] #takes whole line info and adds to list
wholeList.append(line)
greatMag = [] #creating lists for different category magnitudes
majorMag = []
strongMag = []
moderateMag = []
for x in magList: #conditions for seperating magnitude
if x >= 8:
greatMag.append(x)
elif 7 <= x <= 7.9:
majorMag.append(x)
elif 6 <= x <= 6.9:
strongMag.append(x)
elif 5 <= x <= 5.9:
moderateMag.append(x)
for line in wholeList: #takes only magnitude and region name from whole list
combinedList.append([line[7], line[1]])
infoDict = {} #creates dictionary
for key, val in combinedList: #makes one key per region and adds all values corresponding to the region
infoDict.setdefault(key, []).append(val)
print(infoDict)
for k, v in infoDict.items():
for i in v:
if i >= 8:
print("Great Magnitude:", i)
pass
if __name__ == "__main__": #runs main function
main()