Hello I'm trying to make a stem and leaf plot. The first function is supposed to call the other two functions and return the final plot. My code works for the first elemnt in the list and then stops. Is there something I have to do within my for loop? Also I realize that I need an if statement to check for if a number previously exists on the left side then to print the number farther on the right side. Should I assign the left column to a variable? And if so what do i then do on the right side? Any help would be great thanks!

def stem_and_leaf(data):
    def append_num(data): 
        for x in data:
            append_last=str(x)
            return ' %s' %(append_last[-1])
    def new_stem(data):
        for x in data:
            append_first= str(x)
            return '%s |' % (append_first[:-1])
    return new_stem(data)+append_num(data)

Look up yield from python documentation and change return to yield in two helper_functions. Alternatively collect the result in the for in string variable or list.

Success?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.