Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- song = sys.argv[1]
- w = open(song)
- for line in sorted(w, key = int(len(line)))
- print line
- song = sys.argv[1]
- w = open(song)
- for line in sorted(w, key=len)
- print line
- song = sys.argv[1]
- w = open(song)
- for line in sorted(w, key=lambda x: len(x.split()))
- print line
- lines = [line.rstrip().split() for line in file]
- lines = [sorted(line.rstrip().split(), key=len) for line in file]
- lines = sorted((sorted(line.rstrip().split(), key=len) for line in file), key=len)
- for line in lines:
- print ' '.join(line)
- sentences.sort(key=word_count)
- words = get_words(sentence)
- words.sort(key=char_count)
- #!/usr/bin/env python
- import io
- import sys
- with io.open(sys.argv[1]) as file:
- sentences = file.read().splitlines() # NOTE: line ends are not included
- result = sorted([sorted(get_words(s), key=char_count)
- for s in sentences], key=word_count)
- for words in result: # for each sentence
- print(' '.join(words))
- get_words = unicode.split # split on arbitrary whitespace
- word_count = len # number of items in the list of words
- char_count = len # unicode word length
- import re
- words = re.findall(r'w+', sentence, flags=re.UNICODE)
- >>> len(u"ะตฬ")
- 2
- >>> u"ะตฬ"
- u'u0435u0308'
- >>> print(u'U0001f602')
- ๐
- >>> len(_)
- 1
Add Comment
Please, Sign In to add comment