How to convert the following string in python?
<p>Input : UserID/ContactNumber </p>

<p>Output: user-id/contact-number</p>

<p>I have tried the following code:</p>

<pre><code>s ="UserID/ContactNumber"

list = [x for x in s]

for char in list:

     if char != list[0] and char.isupper():
            list[list.index(char)] = '-' + char

 fin_list=''.join((list))
 print(fin_list.lower())
</code></pre>

<p>but the output i got is:</p>

<pre><code>  user-i-d/-contact-number
</code></pre>

<p>I did something like this</p>

<pre><code>s ="UserID/ContactNumber"

new = []
words = s.split("/")

for word in words:
    new_word = ""
    prev = None
    for i in range(0, len(word)):
        if prev is not None and word[i].isupper() and word[i-1].islower():
            new_word = new_word  + "-" + word[i]
            prev = word[i]
            continue
        new_word = new_word  + word[i]
        prev = word[i]
    new.append(new_word.lower())

print "/".join(new)
</code></pre>

<blockquote>
  <p>user-id/contact-number</p>
</blockquote>

python python-2.7 python-3.x