import sys import re input_line = ' '.join(sys.argv[1:]) output_line = ' '.join(re.split('\W+', input_line)[::-1]) print output_line.strip()
For your example work. In general, the task is not entirely correct. My script first merges all the command line arguments into a single line separated by a space, then splits the resulting string into all "non-dictionary characters". It is not clear what you want to get when you run the python script.py for+ce the Fe-el program python script.py for+ce the Fe-el ? In this case, my option will be el Fe the ce for , + not part of the word. Simply if you run python script.py ['feel', 'the', 'force'] then the "input data" will be the lines [feel , the, force] , at least in * nix.
Another question to backfill:
python script.py [1, 2, [3, 4, 5]]
Result:
a) [3, 4, 5] 2 1 b) [[5, 4, 3], 2, 1] c) 5 4 3 2 1
All three options, to one degree or another, are suitable.
P.S. Regular expressions are one of the most difficult topics for a beginner, sorry.
Courses that offer
list.reverse() result = list[0] for item in list[1:]: result += ' ' + item
instead
result = ' '.join(list[::-1])
should be immediately burned at the stake of the sacred inquisition
print ' '.join(['force', 'the', 'Feel'][::-1])displaysFeel the forcewithout brackets and commas. - jfs