pythonlistvariablesif-statementprocedures

Python variable passing between procedures


I'm working on a code that firstly checks first letters of words from a list and letter counts only those that are letter 'U'

Currently I'm facing issue with:

  1. how to make main procedure to pass the input to check_first_letter
  2. how to search the check_first_letter results and count them

code:

def check_first_letter(w):
    return [s[:1] for s in w]

def measure_udacity(methodToRun):
    result = methodToRun()
    return result

print measure_udacity(['Dave','Sebastian','Katy'])

Solution

  • I think you are overcomplicating things. Try this:

    def measure_udacity(names):
        for n in names:
            if n[0] =='U':
                print (n, len(n))
    
    measure_udacity(['Dave','Sebastian','UKaty'])