Live Chat!

Reverse a string

          0 votos

October 9th, 2006 toydi

python provides a -c option to accept and run a script line.
To reverse a string like this one: “toydi deified idiot”.
echo ‘toydi deified idiot’ | python -c “print raw_input()[::-1]”

echo prints the string to stdout.
python run the script line.
raw_input() read from stdin (to read from pipe and return the string).
[::-1] simply says: steps through and [...]

Posted in python, rev | Hits: 5527 | 5 Comments »