python four_letters_in_common.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python four_letters_in_common.py相关的知识,希望对你有一定的参考价值。

def four_letters_in_common(word,a_dictionary):
        count=0
        word=word.upper()
        word_length = len(word)
        if word_length<4:            
            return count
        elif word_length ==4:            
            for entry in a_dictionary:
                entry=entry.upper()
                if entry.find(word)!= -1:
                    count+=1                                  
            return count
        else:
            for entry in a_dictionary:
                entry=entry.upper()
                length = len(entry)
                if length<4:                    
                    pass                
                else:
                    first_position =0
                    last_position =4
                    finalsub=word[-4:-1]
                    current_substring=word[first_position:last_position]
                    while True:                        
                        if entry.find(current_substring)!= -1:
                            count+=1                            
                            break
                        else:
                            first_position +=1
                            last_position +=1                            
                            if last_position>word_length:                                
                                break
                            else:                                
                                current_substring=word[first_position:last_position]
            return count

以上是关于python four_letters_in_common.py的主要内容,如果未能解决你的问题,请参考以下文章

Python代写,Python作业代写,代写Python,代做Python

Python开发

Python,python,python

Python 介绍

Python学习之认识python

python初识