python
List1=[ ["a", 1], ["b", 3], ["c", 3], ["d", 2], ["e", 1], ["f", 4], ["g", 2]]
1 def function(Letter,List),example, function("c",List) return 3
2 def function(word,List),example, function("a",List) return 1, function("be",List) return 4, function("bee",[b,5],[e,20]) return 45
Dictionary = ["a","bee","ad","ae"]
3 ["a","b","y","e"] return[["a",1],["ae",2],["bee",5]]
4 input a list, find largest value words can spell, return words and value
dont using loop,
using recursion for those code
SOURCE CODE:
*Please follow the comments to better understand the code.
**Please look at the Screenshot below and use this code to copy-paste.
***The code in the below screenshot is neatly
indented for better understanding.
# This is the recursive function that calculates the value for a
given word or lette
def helper_recursive(s,itemDict):
# It is a letter
if len(s)==1:
return itemDict.get(s[0])
else:
# It is a word.
# So, call it recursively and add the value of first letter
return itemDict.get(s[0]) + helper_recursive(s[1:],itemDict)
def function(input_list,List):
max_word = ''
max_value = 0
# Convert it to dict for easier access
itemDict = {item[0]: item[1] for item in List}
# print(itemDict)
# For each item in the input list, call the recursive function and
check for the max values
for item in input_list:
# Get the value for that word/letter
h_value = helper_recursive(item,itemDict)
print(item,"has value=>",h_value,'from recursive
"helper_recursive" function')
# Update the max value
if h_value > max_value:
max_word = item
max_value = h_value
# return max word and the value
return max_word, max_value
# Test the function
List1=[ ["a", 1], ["b", 3], ["c", 3], ["d", 2], ["e", 1], ["f", 4],
["g", 2] ]
sol = function(["a","bee","ad","ae"],List1)
print('The Maximum word and value are: ',sol)
======================
SCREENSHOT:


python List1=[ ["a", 1], ["b", 3], ["c", 3], ["d", 2], ["e", 1], ["f", 4], ["g", 2]]...
Python Assignment: def sliceNdice(list2, s,e): L = len(list2) if(s>0 and s<e and e+s<=L): list1 = list2[s:e+s] else: list1 = [ ] return list1 refer to the code above. What is the value of L after line 2 and we call: x = sliceNdice([3,6,9,7] 2,6) 3. Refer to the previous question. What is happening at line 4? 4. For the code shown below: for num in range (1,4): print(num) What is the first value printed
PYTHON Stuck with this problem with these implementation
requirements. PLEASE HELP! THANK YOU! PYTHON
Q7 16 Points Give a python implementation of the following function: def without_Vowels(listi): The above function gets a list of positive integers and English letters, list1. When called, it should remove all the vowels from list1, and keep only the consonants and integers. The Order of the remaining consonants and integers does not matter. For example, if list1 = ['a', 'b', 5, 'c', 'o', 2, 'e',...
write the following code in python 3.2+. Recursive function
prefered. Thank you!
Define a function named q3() that accepts a List of characters as a parameter and returns a Dictionary. The Dictionary values will be determined by counting the unique 3 letter combinations created by combining the values at index 0, 1, 2 in the List, then the values at index 1, 2, 3 and so on. The q3() function should continue analyzing each sequential 3 letter combination and using...
Python: P2 Write a function that reverses a python list using recursion (Chapter 6-3 in our textbook) E.g.: Input: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] Output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Constraints: - List elements are integers - The function should return a reversed array, not print its elements You may use the following code as template: def reverse(my_list, index = None): # your code here
Python. Write a function swap_lists that takes in two lists and swap their elements in place. You can not use another list. You can not return lists. Input lists have the same size. def swap_lists(alist1, alist2): """Swaps content of two lists. Does not return anything. >>> list1 = [1, 2] >>> list2 = [3, 4] >>> swap_lists(list1, list2) >>> print(list1) [3, 4] >>> print(list2) [1, 2] >>> list1 = [4, 2, 6, 8, 90, 45] >>> list2 = [30, 41,...
Must be written in python 3:
#
# Complete the 'SmallestDictionaryOrderedArray' function
below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts following parameters:
# 1. INTEGER_ARRAY a
# 2. INTEGER_ARRAY b
#
def SmallestDictionaryOrderedArray(a, b):
# Write your code here
☆ Dictionary Ordered Array Given two arrays of numbers, we can use "dictionary ordering" to identify which array is "smaller" (similar to which array would come first in a dictionary). Just like the order...
python please
11 def add_item(items, word): 14 15 16 F # check if the word is in the dictionary (keys of dictionary) if word in items: items [word] = items (word] + 1 # update the count else: # word is not in dictionary items[word] = 1 # add the word with count 1 return items [word] # return the current count of word after updation Create a function named build_dictionary that takes a list of words (as a parameter)...
Complete the below function that takes a file name and a list as arguments and reads the text within the corresponding file, then creates a dictionary whose keys are the characters of the provided list, and the values are the counts of these characters within the text. If a character in the list is not included in the text, "0" should be written in the dictionary as the value of this character. The function returns the created dictionary as a result. If the file does not exist, then the function returns an empty dictionary. Here is an example case, assuming a file named "sample.txt" exists with the following content: ----- sample.txt ----- This is an example sentence. This is yet another sentence. ------------------------- >>> text2dict("sample.txt", ['a', 'b', 'c', 't']) {'a':3, 'b':0, 'c':2, 't':4} """ def text2dict(filename, characters): return # Remove this line to answer this question
6 (4 points): 4 3 2 1 0 Use Kruskal's algorithm to find the minimum spanning tree for the graph G defined by V(G) E(G) a, b, c, d, e ac, ad, ae, be, bd, be Vo(ad) = (a, d) (ae) a, e (be) b,e) using the weight function f : E(G)Rgiven by f(ac)-(ad)-3 f(ae)-2 f(be) =4 f(bd) = 5 f(be) = 3
6 (4 points): 4 3 2 1 0 Use Kruskal's algorithm to find the minimum spanning tree...
Solve it in Python 4. An alternade is a word in which its letters, taken alternatively in a strict sequence, and used in the same order as the original word, make up at least two other words. All letters must be used, but the smaller words are not necessarily of the same length. For example, a word with seven letters where every second letter is used will produce a four-letter word and a three-letter word. Here are two examples: "board":...