Question

solve with python

Write a recursive function recStringWithLenCount() that takes a one-dimensional list of strings as a parameter and returns the count of strings that have at least the length of second parameter passed into the function that are found in the list. Recall that you can determine whether an item is a string by writing type(item) == str. The only list functions you are allowed to use are len(), indexing (lst[i] for an integer i), or slicing (lst[i:j] for integers i and j). In particular, the function should not in any way alter the list passed as a parameter. The following shows several sample runs of the function:

recStringwithLenCount(Anthony 1,2) >>> 1 recStringwithLenCount([ab, cd 1,2) 2 recStringwithLenCount([ab, cd 1,1) <AA 2

0 0
Add a comment Improve this question Transcribed image text
Answer #1

(no subject)

me?at=AF6bupOUkgBB_XCs1tzLUTIwi7GRCb7D_A

Vamsi Saikam

to me
0 minutes ago

Details

def recStringWithLenCount(lst,length):
if len(lst)==0:
return 0
if type(lst[0])==str:
if length<=len(lst[0]):
return recStringWithLenCount(lst[1:],length)+1
return recStringWithLenCount(lst[1:],length)
#testing above method
print(recStringWithLenCount(['Anthony'],2))
print(recStringWithLenCount(['ab','cd'],2))
print(recStringWithLenCount(['ab','cd'],1))
print(recStringWithLenCount(['ab','cd'],3))
print(recStringWithLenCount([],3))

main.py 1. def recStringWithLenCount(1st, length if len(1st)==0: return 0 if type(lst[@])==str: if length<=len(1st[@]): retur

Add a comment
Know the answer?
Add Answer to:
solve with python Write a recursive function recStringWithLenCount() that takes a one-dimensional list of strings as...
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
  • A. Write an algorithm in pseudocode, which prints all strings of length 6 where the first...

    A. Write an algorithm in pseudocode, which prints all strings of length 6 where the first three characters are any symbol from X={!,@,#,$,%,^}, the 4th and 5th characters are any digit 0,1,…9, and the last character is any digit 1,2,…9. How many times will the print command be called (e.g. how many 6-character strings will be printed)? B. Let g(n)=n3 + 2n2 - 5. Determine the big-theta estimate of f. A complete response will include analysis of: , and ....

  • For this task you're going to write a function that joins strings from a list. The function calle...

    I need help with this python programming assignment please double check the indentations For this task you're going to write a function that joins strings from a list. The function called join ) has one formal parameter and one optional parameter. Recall that an optional parameter is like end or sep in the print( function. You don't have to use it because there's a default value. For the print () function, e.g., \'n' (newline) is the default value for end....

  • Write a python function alt which takes a list of strings myList as a parameter. alt...

    Write a python function alt which takes a list of strings myList as a parameter. alt then returns two strings s1 and s2 as a tuple (s1, s2). Here s1 is the concatenation of the strings in myList in even index positions, and s2 is the concatenation of the strings in myList in odd index positions. (List starts at index 0) For example, if myList = [‘My’, ‘kingdom’, ‘for’, ‘a’ , ‘horse’], then s1 = ‘Myforhorse’ and s2 = ‘kingdoma’.

  • Write a recursive function sum-odds that takes a non-empty list of integers

    in python Part I: Sum of Odd Integers Write a recursive function sum-odds that takes a non-empty list of integers as an argument and returns the sum of only the odd integers in the list. In class we explored a recursive function called rsum that recursively computes the sum of a list of integers use it as a model to get started. Your function must be recursive and must not use any loops

  • Write a function called find_max that takes a two-dimensional list as a parameter and returns the...

    Write a function called find_max that takes a two-dimensional list as a parameter and returns the number of the row that sums to the greatest value. For example, if you had the following list of lists: list = [[1, 2, 3], [2, 3, 3], [1, 3, 3]] The first row would be 6, the second 8 and the third 7. The function would, therefore, return 1. You can assume the passed in list of lists has at least one row...

  • Write a Python function fun8(k) that gets list of strings k as passwords and returns the...

    Write a Python function fun8(k) that gets list of strings k as passwords and returns the valid passwords in list format. Criteria for checking passwords: 1.) At least 1 letter between [a-z] 2.) At least 1 letter between [A-Z] 3.) At least 1 number between [0-9] 4.) At least 1 character from [$#@] 5.) Minimum length of transaction password: 6 6.) Maximum length of transaction password: 12 7.) No spaces Example: >>>lst=["ABd1234@1", "a F1#,2w3E*", "2We3345"] >>>fun8(lst) [ABd1234@1] *****We are a...

  • Write a function called longest_morse_code_words which takes in a list of strings. The output of longest_morse_code_words...

    Write a function called longest_morse_code_words which takes in a list of strings. The output of longest_morse_code_words should be a list of the strings that were passed in, but ordered by the length of their Morse Code equivalent in descending order. If the length of Morse Code is equal, order the words alphabetically. For convenience, the full table for the 26 letters of the English alphabet is given below: [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] Here's an example: words = ["gin", "zen", "gig", "msg"] longest_morse_code_words(words) #...

  • Python 3.7.3 ''' Problem 3 Write a function called names, which takes a list of strings...

    Python 3.7.3 ''' Problem 3 Write a function called names, which takes a list of strings as a parameter. The strings are intended to represent a person's first and last name (with a blank in between). Assume the last names are unique. The function should return a dictionary (dict) whose keys are the people's last names, and whose values are their first names. For example: >>> dictionary = names([ 'Ljubomir Perkovic', \ 'Amber Settle', 'Steve Jost']) >>> dictionary['Settle'] 'Amber' >>>...

  • More Practice: Writing Lists& Strings . Write a function average_ evens that takes a list of...

    More Practice: Writing Lists& Strings . Write a function average_ evens that takes a list of numbers as parameters, and adds all the even numbers together and returns their average using a list Example function call: print (average_evens (I-2, -3, 4, 0, 1, 2,3 Outputs: 0 Write a function match that takes two strings as a parameter and returns how many letters the strings have in common. You should treat upper and lower case letters as the same letter ('A,...

  • FOR PYTHON: Write a function findMinRow() that takes a two-dimensional list of numbers as a parameter....

    FOR PYTHON: Write a function findMinRow() that takes a two-dimensional list of numbers as a parameter. It returns the index of the minimum row in the list. The minimum row is the row with the smallest sum of elements. If the list has multiple rows that achieve the minimum value, the last such row should be returned. If the list is empty the function should return -1. The following shows several sample runs of the function: Python 3.4.1 Shell File...

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