Python字典在linux系统下的相关介绍


Python字典的用处非常大,在长时间的使用中我们就会发现,他具有广泛的应用范围,超强的适应能力。下面我们就来看看昨天在网上找了个能在linux跑的字典程序,分享一下。Python字典其实是一个很好使的语言。

  1. #!/usr/bin/python  
  2. f=open(‘wordlist’, ‘w’)  
  3. def xselections(items, n):  
  4. if n==0: yield []  
  5. else:  
  6. for i in xrange(len(items)):  
  7. for ss in xselections(items, n-1):  
  8. yield [items[i]]+ss  
  9. Numbers = 48 – 57  
  10. Capital = 65 – 90  
  11. Lower = 97 – 122  
  12. numb = range(48,58)  
  13. cap = range(65,91)  
  14. low = range(97,123)  
  15. choice = 0 
  16. while int(choice) not in range(1,8):  
  17. choice = raw_input(”’  
  18. 1) Numbers  
  19. 2) Capital Letters  
  20. 3) Lowercase Letters  
  21. 4) Numbers + Capital Letters  
  22. 5) Numbers + Lowercase Letters  
  23. 6) Numbers + Capital Letters + Lowercase Letters  
  24. 7) Capital Letters + Lowercase Letters  
  25. : ”’)  
  26. choice = int(choice)  
  27. poss = []  
  28. if choice == 1:  
  29. poss += numb  
  30. elif choice == 2:  
  31. poss += cap  
  32. elif choice == 3:  
  33. poss += low  
  34. elif choice == 4:  
  35. poss += numb  
  36. poss += cap  
  37. elif choice == 5:  
  38. poss += numb  
  39. poss += low  
  40. elif choice == 6:  
  41. poss += numb  
  42. poss += cap  
  43. poss += low  
  44. elif choice == 7:  
  45. poss += cap  
  46. poss += low  
  47. bigList = []  
  48. for i in poss:  
  49. bigList.append(str(chr(i)))  
  50. MIN = raw_input(“What is the min size of the 
    word? “)  
  51. MIN = int(MIN)  
  52. MAX = raw_input(“What is the max size of 
    the word? “)  
  53. MAX = int(MAX)  
  54. for i in range(MIN,MAX+1):  
  55. for s in xselections(bigList,i): f.write(”.
    join(s) + ‘\n’) 

以上就是对Python字典的详细介绍。

评论关闭