Question

please code in python 3 arr = ['ae', 'anana', 'lolololol', 'aaaaa', 'inkinka', 'playplay', 'fruit', 'cucumbers'] alpha...

please code in python 3

arr = ['ae', 'anana', 'lolololol', 'aaaaa', 'inkinka', 'playplay', 'fruit', 'cucumbers']

alpha = ['a', 'e' ]

saved = ['']

using arr and alpha, count how many a,c,e,s dose each element have.

for example,

anana must print out 3

because it have three a

while you are counting, at saved array, you must save top 3 elements that have highest number.

for example,

'ae', 'anana', 'lolololol', 'aaaaa', 'inkinka', 'playplay', 'fruit', 'not']

2 3 0 5 1 2 0 0

since aaaaa, anana have highest and ae and playplay have same number,

saved must have

saved = ['aaaaa', 'anana', 'ae', 'playplay']

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

Python code to perform the above operation is as follows.

Source code:

arr = ['ae', 'anana', 'lolololol', 'aaaaa', 'inkinka', 'playplay', 'fruit', 'cucumbers']

alpha = ['a', 'e', 'c', 's' ]

saved = []

# Counting the characters

char_count_dict = {}

count = 0

for element in arr:

  for char in alpha:

    count += element.count(char)

  print(count) # Printing the count

  char_count_dict[element] = count

  count = 0

# saving top three elements that have highest value to saved array

for i in range(0,3):

  max_value = max(char_count_dict.values())

  keys = [key for key,value in char_count_dict.items() if value == max_value]

  for key in keys:

    saved.append(key)

    del char_count_dict[key]

print(saved) # Printing saved array

Output:

2 3 0 5 1 2 0 4

['aaaaa', 'cucumbers', 'anana']

Screenshot of running code and output:

Development Environment : Googlecolab

Add a comment
Know the answer?
Add Answer to:
please code in python 3 arr = ['ae', 'anana', 'lolololol', 'aaaaa', 'inkinka', 'playplay', 'fruit', 'cucumbers'] alpha...
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
  • Our 1st new array operation/method is remove. Implement as follows: public static boolean remove( int[] arr,...

    Our 1st new array operation/method is remove. Implement as follows: public static boolean remove( int[] arr, int count, int key ) { 1: find the index of the first occurance of key. By first occurance we mean lowest index that contains this value. hint: copy the indexOf() method from Lab#3 into the bottom of this project file and call it from inside this remove method. The you will have the index of the value to remove from the array 2:...

  • JAVA - the program should output as follows: Please enter a seed: 2345 Please enter the...

    JAVA - the program should output as follows: Please enter a seed: 2345 Please enter the size of the array: 1 Array size must be greater than 1. Please reenter: 0 Array size must be greater than 1. Please reenter: -1 Array size must be greater than 1. Please reenter: 8 Please choose an option: 1 Print the array 2 Find the average 3 Find the largest element 4 Count how many times 3 occurred 5 Count how many elements...

  • [Code in C] Help me with this. Not sure what to do. 1 Couting Sort You...

    [Code in C] Help me with this. Not sure what to do. 1 Couting Sort You may have learned some sorting algorithms - such as bubble sort ad quicksort in CS 110 and CS 210. This homework is about counting sort. Let n be the number of elements to be sorted. Bubble sort and quicksort assume tha time, which one is larger and which one is smaller. They make no assumption on the values of the elements t we can...

  • Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory...

    Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int * ) named ptr_1. Use ptr_1 to assign the number 7 to that dynamically allocated integer, and in another line use printf to output the contents of that dynamically allocated integer variable. Write the code to dynamically allocate an integer array of length 5 using calloc or malloc and have it pointed...

  • complete in C++ code Lists Many programming languages have some kind list data structure, which allows...

    complete in C++ code Lists Many programming languages have some kind list data structure, which allows for insertion and deletion of elements, essentially an array that changes size. C++ has vectors, Java has the ArrayList, Python has lists (which is what they're called generically anyway). But how do they really work? All of these actually use arrays, which naturally have immutable lengths. Your Task Your task is to write a function, insert, which inserts a new item into an existing...

  • 2. Write a C++ program, that generates a set of random integers and places them in...

    2. Write a C++ program, that generates a set of random integers and places them in an array. The number of values generated and their range are entered by the user. The program then continually prompts the user for one of the following character commands: a: display all the values I: display the values less than a given value g display the values greater than a given value e: display all odd values o: display all even values q: quit...

  • 1) Which of the following is NOT true about a Python variable? a) A Python variable...

    1) Which of the following is NOT true about a Python variable? a) A Python variable must have a value b) A Python variable can be deleted c) The lifetime of a Python variable is the whole duration of a program execution.   d) A Python variable can have the value None.        2) Given the code segment:        What is the result of executing the code segment? a) Syntax error b) Runtime error c) No error      d) Logic error 3) What...

  • NO ONE HAS PROVIDED THE CORRECT CODE TO PROVIDE THE GIVEN OUTPUT. PLEASE PROVIDE CODE THAT...

    NO ONE HAS PROVIDED THE CORRECT CODE TO PROVIDE THE GIVEN OUTPUT. PLEASE PROVIDE CODE THAT WOULD CAUSE THE HW1.java TO PRINT THE RIGHT DATA.!!! The LinkedList class implements both the List interface and the Stack interface, but several methods (listed below) are missing bodies. Write the code so it works correctly. You should submit one file, LinkedList.java. Do not change the interfaces. Do not change the public method headers. Do not rename the LinkedList class. None of your methods...

  • In this lab, you get to try your hand with some recursion operating on arrays and...

    In this lab, you get to try your hand with some recursion operating on arrays and subarrays. All of the following methods of the class RecursionProblems must be fully recursive, with no loops allowed at all! (If-else statements are okay.) Because these methods are quite short, this last time there are six methods to write instead of the usual four. (The scoring rule is that you start gaining any points for this lab only at the third method that passes...

  • Python code: 1. This question practices the use of a list method. Assign to the variable...

    Python code: 1. This question practices the use of a list method. Assign to the variable grades a list of 10 letter grades from among ‘A’, ‘B’, ‘C’, ‘D’, and ‘F’. For example: grades = [‘A’, ‘F’, ‘C’, ‘F’, ‘A’, ‘B’, ‘A’, ‘C’, ‘A’, ‘B’] Write a Python expression that creates a list named frequency, in which the elements are the number of times each of the letters A, B, C, D and F appear in grades. For example, for...

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