0

Hashtag Generator in Python

Stuck here, any help?? We are creating our own social network application and need to have a hashtag generator program. Complete the program to output the input text starting with the hashtag (#). Also, if the user entered several words, the program should delete the spaces between them. Sample Input code sleep eat repeat Sample Output #codesleepeatrepeat

10th Oct 2020, 3:44 PM
Greezy gree
Greezy gree - avatar
14 Antworten
+ 3
First you can use split method to split each word in a string with spaces. Then join it back with blank strings. Thus will remove every spaces in the string. Then make a list with the first item as #. Then append the string to the end of the array. Then join this array with empty joiners to make it as a whole array. example is attached below https://code.sololearn.com/cjkGT69PyHNC/?ref=app
10th Oct 2020, 3:52 PM
Steve Sajeev
Steve Sajeev - avatar
+ 7
this is a short version, but still has a good readability: print('#'+''.join(input().split())) # or to store the hashtag in a variable: hash_tag = '#'+''.join(input().split())
10th Oct 2020, 5:56 PM
Lothar
Lothar - avatar
+ 6
This is my solution: s = input() def hashtagGen(text): #your code goes here a = text.replace(" ", "") return a print(hashtagGen('#' + s))
10th Jul 2021, 6:50 AM
Attila
Attila - avatar
+ 4
s = input() def hashtagGen(text): return text.replace(" ", " ") print(hashtagGen('#' + s))
21st Jul 2021, 2:43 PM
Peyman Daei Rezaei
Peyman Daei Rezaei - avatar
+ 3
I saw you sharing your attempt but then you removed it. I think this should work. https://code.sololearn.com/cVvQOLBLS19M/?ref=app
10th Oct 2020, 3:59 PM
Avinesh
Avinesh - avatar
+ 2
With replace function you can do that.For # you can added it in the begin to the input and reassign new input to it with space removed
10th Oct 2020, 4:19 PM
HBhZ_C
HBhZ_C - avatar
+ 2
s = input() def hashtagGen(text): #your code goes here a = text.replace(" ", "") return a print(hashtagGen('#' + s))
17th May 2022, 7:31 AM
Najwan Najmussabah
+ 1
I have used this code: s = input() def hashtagGen(text=s): # место для вашего кода i = text.replace(" ", "") i = list(i) h = "#" i.insert(0, h) print(''.join(i)) return hashtagGen(s)
20th Feb 2021, 7:49 PM
Майкл Иззука
+ 1
Its my solution but it is a bit long and complex: def hashtag (text): hash = ["#"] for i in text: if i != " ": hash.append(i) else: continue tag = "" for j in hash: tag += j print(tag) subject = input("enter what's on your mind: ") hashtag(subject)
5th Sep 2021, 8:23 PM
Bekir
Bekir - avatar
+ 1
#Sample Input: code sleep eat repeat #Sample Output: #codesleepeatrepeat user_string = input() def hashtag_generator(x): x = x.replace(" ", "") return "#" + x print(hashtag_generator(user_string))
19th Feb 2022, 5:19 PM
Matumbai Binale
Matumbai Binale - avatar
+ 1
Siva Krishnan , sorry to say, your example is neither a valid *python code* nor a *list comprehension*. so it would be better if you remove it.
17th Aug 2024, 9:19 AM
Lothar
Lothar - avatar
0
Comment=input().split() print("#","".join(comment,sper"')
4th Feb 2021, 6:11 PM
Maruf Ashurov
Maruf Ashurov - avatar
0
text = input("enter the trend: ") def hashtagGen(text): a = text.replace("","") return a print(hashtagGen('#'+text))
18th Sep 2021, 4:43 PM
Seshu Yaswanth Reddy
Seshu Yaswanth Reddy - avatar
0
Code a list comprehension to add a hashtag '#' to the values of the tags list hashtags = [" + X X tags] TAB=1 ( )
17th Aug 2024, 4:27 AM
Siva Krishnan
Siva Krishnan - avatar