Question

in python would you please help me to keep this code as in a simple and...

in python would you please help me to keep this code as in a simple and easy code to follow please

I want the code to run like first line of the letters

['B', 'C', 'D', 'BC', 'CB', 'BD', 'BCB', 'CBD', 'BCBD']  
['B', 'BC', 'BCB', 'BCBD', 'C', 'CB', 'CBD', 'BD', 'D']

word="BCBD"
lst=[]
for i in range(len(word)):
for j in range(i+1,len(word)+1):
if word [i:j] not in lst:
lst.append(word[i:j])
print(lst)

0 0
Add a comment Improve this question Transcribed image text
Answer #1
word="BCBD"
lst=[]
for i in range(1,len(word)+1):
    for j in range(len(word)-i+1):
        if word[j:j+i] not in lst:
            lst.append(word[j:j+i])
print(lst)

['B', 'C', 'D', 'BC', 'CB', 'BD', 'BCB', 'CBD', 'BCBD']

Output:

['B', 'C', 'B', 'D', 'BC', 'CB', 'BD', 'BCB', 'CBD', 'BCBD'] Process finished with exit code o

Add a comment
Know the answer?
Add Answer to:
in python would you please help me to keep this code as in a simple and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • # Python Please help me convert the input values to float values Code works, but the...

    # Python Please help me convert the input values to float values Code works, but the values printed need to be floats like 77.0 etc.    j_list = [] k_list = [] c_list = []    # Enter scores for Jean print("Please enter Jean's scores one by one. ") for i in range(4): j_list.append(eval(input())) print("Jeans scores:", j_list)    # Enter scores for Kayla    print("Please enter Kayla's scores one by one. ") for i in range(4): k_list.append(eval(input())) print("Kayla scores: ",...

  • Hey guys, Question with PYTHON I have this simple code and I keep getting 13 for...

    Hey guys, Question with PYTHON I have this simple code and I keep getting 13 for the answer but the answer is actually 13.33. Can someone show me how to get python to return this value! Thanks ! CN = 75 S = (1000/CN) print S

  • this python code below is to find the longest common subsequence from two input string !!!...

    this python code below is to find the longest common subsequence from two input string !!! however it give me the wrong answer, can any one fix it thanks def lcs(s1, s2): matrix = [["" for x in range(len(s2))] for x in range(len(s1))] for i in range(len(s1)): for j in range(len(s2)): if s1[i] == s2[j]: if i == 0 or j == 0: matrix[i][j] = s1[i] else: matrix[i][j] = matrix[i-1][j-1] + s1[i] else: matrix[i][j] = max(matrix[i-1][j], matrix[i][j-1], key=len) cs =...

  • Using Python, if you could help me with the code # Create a modified version of...

    Using Python, if you could help me with the code # Create a modified version of the search linear function defined # above to return all # occurrences of the search word in the text # An occurrence is the index of a word in the text that matches your given # search string. # e.g. if "hatter" occurs at positions 0, 6, 12 then return [ 0, 6, 12] def search_linear_occurrences(xs, target): """ Find and return a list of...

  • please help, language is python You’re creating a secret code to share with your friends such...

    please help, language is python You’re creating a secret code to share with your friends such that every word should be written with the second and last letters swapped. Write a function called encode that receives a string (input) and prints out another string with the second and last letters swapped. Example function calls: encode(secret) # should print “the code for secret is stcree” encode(city) # should print “the code for city is cyti”

  • PLEASE DESCRIBE THE STEPS IN THE CODE! please.. (simple code) In this homework, the rail fence...

    PLEASE DESCRIBE THE STEPS IN THE CODE! please.. (simple code) In this homework, the rail fence cipher is written in Python. We did implement this already in the class by appending letters sequentially to three different lists, which represented three rails. In this project, you are allowed to implement it in any other way. First step is to drop all the space characters inside the plain text. An easy way to implement it is to notice that the first rail...

  • Python Merge Sort Adjust the following code so that you can create random lists of numbers of lengths 10, 15, and 20. You will run the merge sort 10 times for each length. Record the run time for the...

    Python Merge Sort Adjust the following code so that you can create random lists of numbers of lengths 10, 15, and 20. You will run the merge sort 10 times for each length. Record the run time for the length and then calculate the average time to sort. Finally, compare the average run time for each length to the average time for the Merge Sort. -------------------------------------------- Initial python code: import random import time def mergeSort(alist): print("Splitting ",alist) if len(alist)>1: mid...

  • In python, write the following program, high school question, please keep simple. When I submitted the...

    In python, write the following program, high school question, please keep simple. When I submitted the solution, I get an error as 'wrong answer'. Please note below the question and then the solution with compiler errors. 7.2 Code Practice: Question 2 Instructions Write a program to generate passwords. The program should ask the user for a phrase and number, and then create the password based on our special algorithm. The algorithm to create the password is as follows: If the...

  • Python Problem Hello i am trying to finish this code it does not save guesses or...

    Python Problem Hello i am trying to finish this code it does not save guesses or count wrong guesses. When printing hman it needs to only show _ and letters together. For example if the word is amazing and guess=a it must print a_a_ _ _ _ not a_ _ _ _ and _a_ _ _ separately or with spaces. The guess has a maximum of 8 wrong guesses so for every wrong guess the game must count it if...

  • Python help! I need help getting my code to increment the value. It keep calculating the...

    Python help! I need help getting my code to increment the value. It keep calculating the range over the same number and not moving up! this is the question Write a program named q1() that prompts the user for the starting and ending distance in Kilometers (km), and an increment value. It should then print the conversion table showing values for Kilometers, Miles (M) and Feet (ft). Each value should be displayed as they are calculated. and this is the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT