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

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -