+ 4
Why sep parameter isn't working here in python problem
Question: https://www.sololearn.com/coach/82?ref=app Answer body : var = str(input()) var_1 = var.lower() print (var_1 , sep = "_")
15 Respuestas
+ 3
---> sep Issue: sep doesn't do anything here because you're only dealing with one string, not multiple values to separate.
----> Conversion Logic Missing: Your code should include steps to insert underscores before uppercase letters and turn those letters into lowercase.
https://www.sololearn.com/discuss/3291612/?ref=app
def camel_to_snake(camel_str):
result = []
for char in camel_str:
if char.isupper():
if result:
result.append('_')
result.append(char.lower())
else:
result.append(char)
return ''.join(result)
var = input().strip()
print(camel_to_snake(var))
+ 4
Programming is very dangerous 💀
I'm too beginner for this question 😤🥺
however Muhammad Nouman Ali , A͢J ,Jan ,Bob_Li , and Ержан Базаргали thanks alot for your helpful support 🥰
+ 3
You need to have more than one value argument in the print statement before it works, like this......
print(var_1, var_2, sep="_")
+ 3
A͢J can please share the sample code 🙂🙏
+ 3
Bob_Li I'll surely implement this 🥰 but at first I would learn the concept to understand what functions and methods you've used in this program ☺️ your support is really appreciable and I'm grateful for your help 🙏💖
+ 2
A͢J bhaiya I've inserted the answer below of the question
+ 2
Jan it is not working 😭😭
+ 2
Naina Kapoor That's because you haven't created a var_2 with a value, but you can also just write...
print(var_1, var_1, sep="_")
+ 2
Naina Kapoor
you must have more than 1 item to print, otherwise there is nothing to separate.
print(1,2,3,4, sep='_')
in your example, you are only printing var1
+ 2
Naina Kapoor
you can still use sep if you are just printing the result for a camel to snake conversion.
def c2s(s):
n=0
res=[]
for i,e in enumerate(s):
if e.isupper():
res.append(s[n:i].lower())
n = i
res.append(s[n:].lower())
print(*res, sep='_')
var = input().strip()
c2s(var)
s1 = 'weNeedToConvertToSnakeCase'
c2s(s1)
+ 1
We cannot see others code coach solution using the links.
+ 1
Naina Kapoor
sep will not work like that
You have to use formatter like this
f"_{var}"
But you have to iterate string and check if a character is in upper case then use formatter to replace that character with _
+ 1
Look at the difference:
print("hello!, sep="_" ) #hello
print("hello", "world", sep="_") #hello_world
+ 1
Fareedah Olusunmade
Tapha Sarr
Do not spam
+ 1
Naina Kapoor
it's called slicing . it works for lists and strings to chop up parts you need.