-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsort_list.py
executable file
·36 lines (30 loc) · 1.05 KB
/
sort_list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
# -*- coding: utf-8 -*-
###################################################################################
# Gives last one and two words in sentence
#
# Author: David S. Brown
####################################################################################
import os
import sys
import argparse
parser = argparse.ArgumentParser(description="Read a file print last words")
parser.add_argument("-d", "--debug", action='store_true', default=False, help="Set debug on")
parser.add_argument("-f", "--file", default=False, help="Read from this file.")
# Prints help if no arguments
if len(sys.argv)==1:
parser.print_help()
sys.exit(1)
args = parser.parse_args()
makes_len = {}
if args.file:
with open(args.file,'r') as f:
for line in f:
line = line.rstrip('\n').strip()
if len(line) in makes_len:
makes_len[len(line)].append(line)
else:
makes_len[len(line)]=[line]
for k in sorted(makes_len.keys(), reverse=True):
for i in makes_len[k]:
print i