Python字典在linux系統下的相關介紹
作者:佚名
Python字典在使用的時候我們有不少需要注意的地方。當然我們在的使用的時候只要注意源代碼的編寫就能更好的使用這個語言。
Python字典的用處非常大,在長時間的使用中我們就會發現,他具有廣泛的應用范圍,超強的適應能力。下面我們就來看看昨天在網上找了個能在linux跑的字典程序,分享一下。Python字典其實是一個很好使的語言。
- #!/usr/bin/python
- f=open(‘wordlist’, ‘w’)
- def xselections(items, n):
- if n==0: yield []
- else:
- for i in xrange(len(items)):
- for ss in xselections(items, n-1):
- yield [items[i]]+ss
- # Numbers = 48 – 57
- # Capital = 65 – 90
- # Lower = 97 – 122
- numb = range(48,58)
- cap = range(65,91)
- low = range(97,123)
- choice = 0
- while int(choice) not in range(1,8):
- choice = raw_input(”’
- 1) Numbers
- 2) Capital Letters
- 3) Lowercase Letters
- 4) Numbers + Capital Letters
- 5) Numbers + Lowercase Letters
- 6) Numbers + Capital Letters + Lowercase Letters
- 7) Capital Letters + Lowercase Letters
- : ”’)
- choice = int(choice)
- poss = []
- if choice == 1:
- poss += numb
- elif choice == 2:
- poss += cap
- elif choice == 3:
- poss += low
- elif choice == 4:
- poss += numb
- poss += cap
- elif choice == 5:
- poss += numb
- poss += low
- elif choice == 6:
- poss += numb
- poss += cap
- poss += low
- elif choice == 7:
- poss += cap
- poss += low
- bigList = []
- for i in poss:
- bigList.append(str(chr(i)))
- MIN = raw_input(“What is the min size of the
word? “)- MIN = int(MIN)
- MAX = raw_input(“What is the max size of
the word? “)- MAX = int(MAX)
- for i in range(MIN,MAX+1):
- for s in xselections(bigList,i): f.write(”.
join(s) + ‘\n’)
以上就是對Python字典的詳細介紹。
【編輯推薦】
責任編輯:張浩
來源:
CSDN