0

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)
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by pyTony
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.