+ 5

JUNGLE CAMPING

I solved the jungle camping puzzle, but I'm wondering if anyone can tell me if there's an easier/more streamlined way this could have been done. Thanks in advance. Link to challenge: https://www.sololearn.com/coach/45?ref=app My solution: https://code.sololearn.com/cR7qwfC4f4Qb/?ref=app

28th Mar 2020, 10:10 PM
Élysse Marcellin
Élysse Marcellin - avatar
10 Respostas
+ 9
I went for this noise = {'Grr':'Lion', 'Rawr':'Tiger', 'Ssss':'Snake', 'Chirp':'Bird'} entry = input() p = entry.split() for x in p: if x in noise: print ((noise[x]), end=" ")
11th Sep 2020, 10:34 AM
Keith Cooper
Keith Cooper - avatar
+ 8
You could have used the replace() method. print(what_animal.replace("Grr", "Lion).replace("Rawr", "Tiger)...) Nothing wrong with what you did, though!
28th Mar 2020, 10:42 PM
Russ
Russ - avatar
+ 7
I did it this way noise = str(input()) noise_list = noise.split() animal = {"Grr":"Lion", "Ssss":"Snake", "Rawr":"Tiger", "Chirp":"Bird"} answer = " " for x in noise_list: answer += animal[x] + " " print(answer)
10th Jun 2020, 6:59 PM
John McCormack
John McCormack - avatar
+ 4
This is what I did, using replace() string = input() a = string.replace('Grr', 'Lion') b = a.replace('Rawr', 'Tiger') c = b.replace('Ssss', 'Snake') d = c.replace('Chirp', 'Bird') print(d)
9th Aug 2020, 4:58 PM
Johan
Johan - avatar
+ 2
đŸ‘‰đŸ»Pleased kindly❀upvoteđŸ‘ˆđŸ» I did it using function,any other suggestions are highly welcomeđŸâ–«ïžâ–«ïžâ–«ïž https://code.sololearn.com/cBuE0jHEnNDY/?ref=app
16th Jan 2021, 2:43 PM
Samuel Mathew
Samuel Mathew - avatar
+ 1
Thanks Russ! I'm going to try that. I figured there's got to be another method I could use that would have shortened what I wrote.
28th Mar 2020, 11:50 PM
Élysse Marcellin
Élysse Marcellin - avatar
+ 1
sound = list(input()) for x in sound: if x == "G": print("Lion" , end = ' ') elif x == "R": print("Tiger" , end = ' ') elif x == "S": print("Snake" , end = ' ') elif x == "C": print("Bird" , end = ' ')
22nd Mar 2022, 11:01 AM
Max Im
+ 1
noises = input().split() #The noises are given all in one sentence, so I put them separately in a list animals = { 'Grr': 'Lion', 'Rawr': 'Tiger', 'Ssss': 'Snake', 'Chirp': 'Bird' } #A dictionary to compare the inputs' sounds animals_selected = [ ] #We'll use it later for i in noises: #For each noise in noises if i in animals.keys(): #If the noise is in animals' keys animals_selected.append(animals[i]) #Add its value to animals_selected print(*animals_selected) #The * assures that every item will be printed at the same line, without [] or , or ' just like the puzzle requires.
7th May 2022, 1:53 PM
Gabriel Noberto
Gabriel Noberto - avatar
0
Here you go! Done in Python. I'll try c++ and Java next. import re #Produced By Joe Hutchens word = input() word.strip("") #This extra material. You can rewrite the program with these lines of code# pattern = r"Grr+|Ssss+|Rawr+|Chirp+" x1 = re.findall(pattern,word) #This is where the conversion happens# word = re.sub("Grr","Lion",word) word = re.sub("Ssss","Snake",word) word = re.sub("Rawr","Tiger",word) word = re.sub("Chirp","Bird",word) #This will print the completed list with correct wording# print(word)
21st Apr 2021, 7:12 PM
Joe Hutchens
Joe Hutchens - avatar
- 1
my code in python sounds={'Grr' : 'Lion', 'Rawr' : 'Tiger', 'Ssss' : 'Snake', 'Chrip' : 'Bird'} hear=input() animals=[] slist= list(hear.split(" ")) for s in slist: animals.append(sounds.get(s)) output=' '.join([str(i) for i in animals]) print(output)
1st Feb 2021, 6:07 PM
Um Yusuf
Um Yusuf - avatar