raw input - Printing results in reverse order from raw_input in python -
when using raw_input
in loop, until character typed (say 'a'
), how can print inputs before that, in reverse order, without storing inputs in data structure?
using string simple:
def foo(): x = raw_input("enter character: ") string = "" while not (str(x) == "a"): string = str(x) + "\n" + string x = raw_input("enter character: ") print string.strip()
but how same without string?
this not practical approach, since asked it:
def getchar(): char = raw_input("enter character: ") if char != 'a': getchar() print char getchar()
of course means i'm using "hidden" data structures, local namespace , call stack.
Comments
Post a Comment