因此,我编写了一个代码,它可以这样做,但似乎不能将这个thisDoesAThing转换成this_does_a_thing,而是给出一个类似于thisDoesA_thing的输出,所以请帮帮我,这是我的代码:
import string
test = input("Enter your camelCasing")
loop = 1
x = string.ascii_uppercase
m = list(x)
for i in m:
while True:
while i in test and loop < 2:
loop +=1
n = i.lower()
j = test.replace(i,"_"+n)
print(j)发布于 2022-10-15 08:37:31
这是你要实现的部分。注:不需要嵌套循环。
let output be an empty string
for each symbol in input
if symbol is uppercase
unless this is a first symbol, append '_' to the output
convert symbol to lower case
append symbol to the output发布于 2022-10-15 08:42:34
这是@gog建议的python中算法的一个类似的实现。
test = input("Enter your camelCasing")
ans=''
for i in range(len(test)):
if test[i].isupper():
if i==0:
ans+=test[i].lower()
else:
ans+="_"+test[i].lower()
else:
ans+=test[i]
print(ans)https://stackoverflow.com/questions/74077912
复制相似问题