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
14 Respuestas
+ 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
+ 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())
+ 6
This is my solution:
s = input()
def hashtagGen(text):
#your code goes here
a = text.replace(" ", "")
return a
print(hashtagGen('#' + s))
+ 4
s = input()
def hashtagGen(text):
return text.replace(" ", " ")
print(hashtagGen('#' + s))
+ 3
I saw you sharing your attempt but then you removed it. I think this should work.
https://code.sololearn.com/cVvQOLBLS19M/?ref=app
+ 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
+ 2
s = input()
def hashtagGen(text):
#your code goes here
a = text.replace(" ", "")
return a
print(hashtagGen('#' + s))
+ 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)
+ 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)
+ 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))
+ 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.
0
Comment=input().split()
print("#","".join(comment,sper"')
0
text = input("enter the trend: ")
def hashtagGen(text):
a = text.replace("","")
return a
print(hashtagGen('#'+text))
0
Code a list comprehension to add a hashtag '#' to the values of the tags list
hashtags = [" + X X tags]
TAB=1
(
)