Here's my first Python program, a little utility that converts from a Unix octal code for file permissions to the symbolic form:
s=raw_input("Octal? ");
digits=[int(s[0]),int(s[1]),int(s[2])];
lookup=['','x','w','wx','r','rx','rw','rwx'];
uout='u='+lookup[digits[0]];
gout='g='+lookup[digits[1]];
oout='o='+lookup[digits[2]];
print(uout+','+gout+','+oout);
Are there ways to shorten this code that take advantage of some kind of "list processing"? For example, to apply the int
function all at once to all three characters of s
without having to do explicit indexing. And to index into lookup
using the whole list digits
at once?