1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
wariber [46]
2 years ago
3

Two strings are anagrams if they are permutations of each other. For example, "aaagmnrs" is an anagram of "anagrams". Given an a

rray of strings, remove each string that is an anagram of an earlier string, then return the remaining array in sorted order. For example, given the strings s = ['code', 'doce', 'ecod', 'framer', 'frame'], the strings 'doce' and 'ecod' are both anagrams of 'code' so they are removed from the list. The words 'frame' and 'framer' are not anagrams due to the extra 'r' in 'framer', so they remain. The final list of strings in alphabetical order is ['code', 'frame', 'framer'].

Computers and Technology
1 answer:
Alex2 years ago
4 0

Answer:

Here is the Python program:

def removeAnagram(array):  #method to remove string from array of strings that is anagram of earlier string

   s = set()  #creates a set

   output = []  #creates an output list

   for string in array:  # iterates through each string in array of strings

       if ''.join(sorted(string)) not in s:  #if sorted string of array is not in s

           output.append(string)  #append that string to output list

           s.add(''.join(sorted(string)))  #add that sorted string to s set

   return sorted(output)  #returns output list

   

array = ['code', 'doce', 'ecod', 'framer', 'frame']  #creates a list of words

print(removeAnagram(array))  #calls method to remove each string that is an anagram of earlier string

Explanation:

I will explain the program with an example:

Suppose array = ['code', 'doce', 'ecod', 'framer', 'frame']

Now the for loop works as follows:

At first iteration:

first string of array is 'code'

if ''.join(sorted(string)) not in s: this is an if statement which has two method i.e. join() and sorted(). First each letter of the string i.e. 'code' is sorted in alphabetical order then these separated characters are joined together into a word with join() method. So

sorted(string) becomes:

['c', 'd', 'e', 'o']                                                                                                           and ''.join(sorted(string)) becomes:

cdeo

Now if ''.join(sorted(string)) not in s condition checks if cdeo is not in s set. This is true so the statement:

output.append(string) executes which appends the string to output list. So now output has:

['code']                                                                                                                         Next s.add(''.join(sorted(string))) statement  adds the sorted and joined string of array to s set. So the set has:

{'cdeo'}                                                                                                                        

So at each iteration each word from the array is sorted and joined and then checked if output array contains that word or not. If not then it is added to the output array otherwise not. For example at 2nd iteration the word 'doce' which is anagram of code and it is checked when it is sorted and joined and it becomes cdeo which is already in output array. So this is how the anagram is removed from the array. At the end the output array which returns the remaining array in sorted order is returned by this method. The screenshot of the program along with its output is attached.

You might be interested in
Using a database of precomputed hashes from sequentially calculated passwords called a(n) __________, an attacker can simply loo
shepuryov [24]
Using a database of precomputed hashes from sequentially calculated passwords called a rainbow table, an attacker can simply look up a hashed password and read out the text version. Each column in the rainbow table uses a different reduction function. The function of the table is <span>reversing cryptographic hash functions. </span>
5 0
3 years ago
1. What is the main factor that affects Earth’s average temperature?
user100 [1]

Answer:

1. The Sun is the primary source of energy that influences any planet's temperature, including Earth. The amount of energy received from the Sun is called insolation; the ratio reflected is called the albedo.

2.There are three major ways in which global warming will make changes to regional climate: melting or forming ice, changing the hydrological cycle (of evaporation and precipitation) and changing currents in the oceans and air flows in the atmosphere

3.The warming of Earth is primarily due to accumulation of heat-trapping greenhouse gases, and more than 90 percent of this trapped heat is absorbed by the oceans. As this heat is absorbed, ocean temperatures rise and water expands. This thermal expansion contributes to an increase in global sea level.

4.The main sources of greenhouse gases due to human activity are: burning fossil fuels leading to higher carbon dioxide concentrations. farming and forestry — including land use change via agriculture and livestock. cement manufacture.

5. - Reduce, Reuse, Recycle

- Use Less Heat and Air Conditioning

-Use Less Hot Water

Explanation:

5 0
3 years ago
PLEASE HELP!! Computer science test
tatiyna

Answer:

See Explanation

Explanation:

Given

The attached function

What the recursion does is that; it adds up individual digits from N to 0

Solving (a): Each output when N = 6

For N = 6.

The function returns the following values:

f(6) = 6

Then: 6 + f(5)

Then: 6 + 5 + f(4)

Then: 6 + 5 + 4 + f(3)

Then: 6 + 5 + 4 + 3 + f(2)

Then: 6 + 5 + 4 + 3 + 2 + f(1)

Then: 6 + 5 + 4 + 3 + 2 + 1 + f(0)

Then: 6 + 5 + 4 + 3 + 2 + 1 + 0 = 21

Solving (b): The output when N = 7

Using the same process in (a) above.

The output is 28

6 0
3 years ago
The one who will defeat me in this typing race I will mark the one brainliest:
fredd [130]

Answer:

yes

Explanation:

can you send the link....

5 0
2 years ago
Read 2 more answers
Design and implement a class dayType that implements the day of the week in a program. The class dayType should store the day, s
Afina-wow [57]

The code is implemented based on the given operations.

Explanation:

#include <iostream>

#include <string>

using namespace std;

class dayType

{ private:

 string day[7];

 string presentDay;

 int numofDays;

public:

 void setDay(string freshDay);

 void printDay() const;

 int showDay(int &day);

 int nextDay(int day);

 int prevDay(int day) const;

 int calcDay(int day, int numofDays);    

 dayType()

 {

  day[0] = "Sunday";

  day[1] = "Monday";

  day[2] = "Tuesday";

  day[3] = "Wednesday";

  day[4] = "Thursday";

  day[5] = "Friday";

  day[6] = "Saturday";

  presentDay = day[0];

  numofDays = 0;

 };

 ~dayType();

};

#endif

#include "dayType.h"

void dayType::setDay(string freshDay)

{

  presentDay = freshDay;

}

void dayType::printDay()

{

  cout << "Day chosen is " << presentDay << endl;

}

int dayType::showDay(int& day)

{

  return day;

}

int dayType::nextDay(int day)

{

day = day++;

if (day > 6)

 day = day % 7;

switch (day)

{

case 0: cout << "The successive day is Sunday";

 break;

case 1: cout << "The successive day is Monday";

 break;

case 2: cout << "The successive day is Tuesday";

 break;

case 3: cout << "The successive day is Wednesday";

 break;

case 4: cout << "The successive day is Thursday";

 break;

case 5: cout << "The successive day is Friday";

 break;

case 6: cout << "The successive day is Saturday";

 break;

}

cout << endl;

return day;

}

 

int dayType::prevDay(int day)

{

day = day--;

switch (day)

{

case -1: cout << "The before day is Saturday.";

 break;

case 0: cout << "The before day is Saturday.";

 break;

case 1: cout << "The before day is Saturday.";

 break;

case 2: cout << "The before day is Saturday.";

 break;

case 3: cout << "The before day is Saturday.";

 break;

case 4: cout << "The before day is Saturday.";

 break;

case 5: cout << "The before day is Saturday.";

 break;

default: cout << "The before day is Saturday.";

}

cout << endl;

return day;

}

int dayType::calcDay(int addDays, int numofDays)

{

addDay = addDays + numofDays;

if (addDay > 6)

 addDay = addDay % 7;

switch(addDay)

{

case 0: cout << "The processed day is Sunday.";

 break;

case 1: cout << "The processedday is Monday.";

 break;

case 2: cout << "The processedday is Tuesday.";

 break;

case 3: cout << "The processedday is Wednesday.";

 break;

case 4: cout << "The processedday is Thursday.";

 break;

case 5: cout << "The processedday is Friday.";

 break;

case 6: cout << "The processedday is Saturday.";

 break;

default: cout << "Not valid choice.";

}

cout << endl;

return addDays;

}

4 0
2 years ago
Other questions:
  • Which of the following is most likely to be a result of hacking? Group of answer choices slowing of network speed certain Web si
    13·1 answer
  • What is the name of the popular DBMS (database management system) that is open source and is distributed under the General Publi
    15·1 answer
  • Dynamic alliance networks work best in industries: a. that are mature and stable in nature. b. where the coordination of product
    9·1 answer
  • You have just installed a new NIC in your PC to replace the old one that had started malfunctioning. What additional software mu
    15·1 answer
  • What is the cell reference for row 22 and column B? __________<br><br> In excel
    5·1 answer
  • The difrent between valid deductive argument and strong inductive argument? At least 2 example​
    6·1 answer
  • Ten examples of an interpreter
    8·1 answer
  • A good practice when using public domain content is to
    7·1 answer
  • 1.1 give five (5) reasons why modeling is an important part of system analysis and design
    9·1 answer
  • Identify the network and the host address in the ip address of 12.128.120.131 with a subnet mask of 255.128.0.0.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!