curriculum/challenges/english/blocks/daily-coding-challenges-python/69272dcf1c24b44fd79137c3.md
Given a string representing a variable name, return the variable name converted to SCREAMING_SNAKE_CASE.
The given variable names will be written in one of the following formats:
camelCasePascalCasesnake_casekebab-caseIn the above formats, words are separated by an underscore (_), a hyphen (-), or a new word starts with a capital letter.
To convert to SCREAMING_SNAKE_CASE:
_)to_screaming_snake_case("userEmail") should return "USER_EMAIL".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_screaming_snake_case("userEmail"), "USER_EMAIL")`)
}})
to_screaming_snake_case("UserPassword") should return "USER_PASSWORD".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_screaming_snake_case("UserPassword"), "USER_PASSWORD")`)
}})
to_screaming_snake_case("user_id") should return "USER_ID".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_screaming_snake_case("user_id"), "USER_ID")`)
}})
to_screaming_snake_case("user-address") should return "USER_ADDRESS".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_screaming_snake_case("user-address"), "USER_ADDRESS")`)
}})
to_screaming_snake_case("username") should return "USERNAME".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_screaming_snake_case("username"), "USERNAME")`)
}})
to_screaming_snake_case("my_variable_name") should return "MY_VARIABLE_NAME".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_screaming_snake_case("my_variable_name"), "MY_VARIABLE_NAME")`)
}})
def to_screaming_snake_case(variable_name):
return variable_name
import re
def to_screaming_snake_case(variable_name):
temp = re.sub(r'[-_]+', ' ', variable_name)
temp = re.sub(r'([a-z0-9])([A-Z])', r'\1 \2', temp)
words = temp.strip().split()
return '_'.join(words).upper()