欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python 窮舉指定長度的密碼例子

 更新時(shí)間:2020年04月02日 09:22:41   作者:lacoucou  
這篇文章主要介紹了python 窮舉指定長度的密碼例子,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧

本程序可根據(jù)給定的字符字典,窮舉指定長度的所有字符串:

def get_pwd(str, num):
  if(num == 1):
   for x in str:
    yield x
  else:
   for x in str:
    for y in get_pwd(str, num-1):
     yield x+y
 
strKey="abc"
for x in get_pwd(strKey,3):
 print x

結(jié)果:

aaa
aab
aac
aba
abb
abc
aca
acb
acc
baa
bab
bac
bba
bbb
bbc
bca
bcb
bcc
caa
cab
cac
cba
cbb
cbc
cca
ccb
ccc

本程序占用內(nèi)存小,生成速度快,歡迎嘗試?。?!

補(bǔ)充知識(shí):Python 窮舉法, 二分法 與牛頓-拉夫遜方法求解平方根的性能對比

窮舉法, 二分法 與牛頓-拉夫遜方法求解平方根的優(yōu)劣,從左到右依次遞優(yōu)。

經(jīng)過測試,窮舉法基本超過 1 分鐘,還沒有出數(shù)據(jù);

二分法只要區(qū)區(qū)1秒不到就出結(jié)果了。

牛頓-拉夫遜是秒出,沒有任何的停頓。

numberTarget =int(input("Please enter a number:"))
numberSqureRoot = 0
while(numberSqureRoot<abs(numberTarget)):
 if numberSqureRoot**2 >= abs(numberTarget):
  break
 numberSqureRoot = numberSqureRoot + 1

if numberSqureRoot**2 != numberTarget:
 print("Your number %s is not a perfect squre, the square root is %s " % ( numberTarget,numberSqureRoot) )
else:
 if numberTarget < 0 :
  numberSqureRoot = -numberSqureRoot
 print("Your number %s is a perfect squre, the square root is %s " % ( numberTarget, numberSqureRoot))

print("now we begin to calculate the binary search...")

numberTarget=int(input("Please enter the number for binary search..."))
numberSqureRoot = 0

lowValue = 0.0
highValue=numberTarget*1.0

epsilon = 0.01
numberSqureRoot = (highValue + lowValue)/2

while abs(numberSqureRoot**2 - numberTarget) >=epsilon:
 print("lowValue:%s, highValue:%s, currentValue:%s"%(lowValue,highValue,numberSqureRoot))
 if numberSqureRoot**2<numberTarget:
  lowValue=numberSqureRoot
 else:
  highValue=numberSqureRoot
 numberSqureRoot = (lowValue+highValue) /2

print("The number %s has the squre root as %s " %(numberTarget,numberSqureRoot))


print("now we begin to calculate the newTon search...")

numberTarget=int(input("Please enter the number for newTon search..."))
numberSqureRoot = 0

epsilon = 0.01
k=numberTarget
numberSqureRoot = k/2.0

while( abs(numberSqureRoot*numberSqureRoot - k)>=epsilon):
 numberSqureRoot=numberSqureRoot-(((numberSqureRoot**2) - k)/(2*numberSqureRoot))

print("squre root of %s is %s " %(numberTarget,numberSqureRoot))

以上這篇python 窮舉指定長度的密碼例子就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • python自動(dòng)12306搶票軟件實(shí)現(xiàn)代碼

    python自動(dòng)12306搶票軟件實(shí)現(xiàn)代碼

    這篇文章主要為大家詳細(xì)介紹了python自動(dòng)12306搶票軟件的實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-02-02
  • 使用Pycharm+PyQt5彈出子窗口的程序代碼

    使用Pycharm+PyQt5彈出子窗口的程序代碼

    這篇文章主要介紹了使用Pycharm+PyQt5彈出子窗口的解決方法,本文通過示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-10-10
  • python PyQt5 爬蟲實(shí)現(xiàn)代碼

    python PyQt5 爬蟲實(shí)現(xiàn)代碼

    這篇文章主要介紹了python PyQt5 爬蟲實(shí)現(xiàn)代碼,代碼簡單易懂,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-04-04
  • python數(shù)據(jù)結(jié)構(gòu)之搜索講解

    python數(shù)據(jù)結(jié)構(gòu)之搜索講解

    這篇文章主要介紹了python數(shù)據(jù)結(jié)構(gòu)之搜索講解,搜索是指從元素集合中找到某個(gè)特定元素的算法過程。搜索過程通常返回?True?或?False,?分別表示元素是否存在,下面一起來了解文章的詳細(xì)內(nèi)容吧,希望對你有所幫助
    2021-12-12
  • Python使用MoviePy實(shí)現(xiàn)編輯音視頻并添加字幕

    Python使用MoviePy實(shí)現(xiàn)編輯音視頻并添加字幕

    MoviePy是一個(gè)用于視頻編輯的Python模塊,它可被用于一些基本操作,本文主要介紹了如何使用編輯音視頻并添加字幕,感興趣的小伙伴可以了解下
    2024-01-01
  • python 提取視頻中的音頻工具類詳解

    python 提取視頻中的音頻工具類詳解

    本文主要介紹了如何利用Python的ffmpy庫實(shí)現(xiàn)提取視頻中的音頻,從而幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下
    2021-11-11
  • 人臉檢測實(shí)戰(zhàn)終極之OpenCV+Python實(shí)現(xiàn)人臉對齊

    人臉檢測實(shí)戰(zhàn)終極之OpenCV+Python實(shí)現(xiàn)人臉對齊

    這篇文章主要是為了演示如何使用 OpenCV、Python 和面部標(biāo)志從而實(shí)現(xiàn)對齊人臉。文中示例代碼對我們的工作或?qū)W習(xí)有一定的幫助,感興趣的小伙伴可以學(xué)習(xí)一下
    2021-12-12
  • python引用DLL文件的方法

    python引用DLL文件的方法

    這篇文章主要介紹了python引用DLL文件的方法,涉及Python調(diào)用dll文件的相關(guān)技巧,需要的朋友可以參考下
    2015-05-05
  • Python with關(guān)鍵字,上下文管理器,@contextmanager文件操作示例

    Python with關(guān)鍵字,上下文管理器,@contextmanager文件操作示例

    這篇文章主要介紹了Python with關(guān)鍵字,上下文管理器,@contextmanager文件操作,結(jié)合實(shí)例形式分析了Python使用with關(guān)鍵字及上下文管理器、contextmanager進(jìn)行文件打開、讀寫、關(guān)閉等操作的相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2019-10-10
  • 淺談Python 的枚舉 Enum

    淺談Python 的枚舉 Enum

    下面小編就為大家?guī)硪黄獪\談Python 的枚舉 Enum。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-06-06

最新評論