1#!/usr/bin/python
2
3aTuple = (123, 'xyz', 'zara', 'abc');
4aList = list(aTuple)
5print "List elements : ", aList
1>>> source_list = [('1','a'),('2','b'),('3','c'),('4','d')]
2>>> list1, list2 = zip(*source_list)
3>>> list1
4('1', '2', '3', '4')
5>>> list2
6('a', 'b', 'c', 'd')
7
1import string
2fhand = open('romeo-full.txt')
3counts = dict()
4for line in fhand:
5 line = line.translate(None, string.punctuation)
6 line = line.lower()
7 words = line.split()
8 for word in words:
9 if word not in counts:
10 counts[word] = 1
11 else:
12 counts[word] += 1
13
14# Sort the dictionary by value
15lst = list()
16for key, val in counts.items():
17 lst.append( (val, key) )
18
19lst.sort(reverse=True)
20
21for key, val in lst[:10] :
22 print key, val
23