Hurricane Analysis Challenge Project (Python)

Hi, here is my code.
Any suggestions, I am never sure if this are best solutions or there is any better “Pythonic” way. Thanks

What did people do this project in? Like what’s recommended? My laptop screen diagonal is only 12" lol so I’m struggling to do it on Codecademy. I’m trying to use Spyder but not finding it great. What did other people use?

my solution. great exercise

A little upgraded solution. One scaling function can process both deaths and damage for to rate hurricanes (starts at line 135). Also it is possible to update scale dictionaries and it will still work :slight_smile:

Wanted to add in the link to my solution (I made a github repo where I will be adding the solutions to all the challenges on this data science track), I have changed a couple of things and used some list comprehensions to make it tidier, left some comments in there too to explain my logic. In some cases, I used the actual list in the definition instead of using the hurricane dictionary for information since these are global functions.

My first post on Codecademy forums and first share using GitHub, so let’s see if I mess something up on either end :upside_down_face:
Hurricane Analysis

This one was really hard. It took me almost a week to complete.
But… here it is. FInally:

Hurricaine Analysis
(Yes, i do realize my spelling is… not cnsistent on the “Hurrcane” word)

I assume that the project does not need the use of Pandas (and DataFrames) and numpy stuff,
although that seems like it would be an interesting way to approach this too.

Here it is my completed project! :blush:

Huuricane Analysis

Here is my solution:

I just have a quiestion about how to sort the damages list?
I had to convert the “Damages not registered” to zeros, but is there another more realistic solution?

BTW this project took me a while, about a week to solve it completely. But it was worth it!

Here is my solution! Have a looksee. I completely forgot about the .find() function but other than that I like what I made. Comments welcome :slight_smile:

For the Hurricane Analysis Challenge Project

Here’s a version of the solution to just part #3 using stuff from the Intermediate Python course.
I think that it’s complete overkill for this project, but I did it anyway.
And I used a dict comprehension in there too.

import inspect

# from 
  # function to get the name(s) of a variable or value
def retrieve_var(val, use_locals=False):
  if use_locals:
    callers_local_vars = inspect.currentframe().f_back.f_locals.items()
    callers_local_vars = inspect.currentframe().f_back.f_globals.items()
  names = [var_name for var_name, var_val in callers_local_vars if var_val is val]
  if len(names) == 1:
    return names[0]
  return names

# args is lists
def make_dict_from_lists(*args, keysource = None ):
  list_names = list(map(retrieve_var, args))

  def fix_name(text):  # function defined inside a function
    result = text.replace('_', ' ').title().strip()
    if result[-1] == 's':
      return result[:-1]
      return result
  keys = list(map(fix_name, list_names))
  pairs = list(zip(keys, args))

  if keysource is None:
    keysource = args[0] #previously args[-1]
  dictionary = dict()
  length = len(keysource)
  for i in range(length):
    dictionary[keysource[i]] = \
      { key: list[i] for key, list in pairs }
  return dictionary

hurricane_dict = make_dict_from_lists(names, months, years, max_sustained_winds, areas_affected, deaths)

print(hurricane_dict['Cuba I'], '\n')
print(hurricane_dict['Ivan'], '\n')

Note that this is not actually what I used in my project; I did something simpler there.

I’m curious if anyone did something similar to the stuff here
or if anyone has any thoughts about this.

Very useful exercise. Here’s my code:

Heres my code… everything works, i think

Super cool project. I learned so much, despite it taking forever. Haha.

Great exercise!

Hurricane Analysis