| Bytes | Lang | Time | Link |
|---|---|---|---|
| 035 | Python 2 | 240925T045015Z | Inertial |
| 046 | PowerShell | 231110T104513Z | Mark Har |
| 036 | Python | 231108T163451Z | bsoelch |
| 035 | Python 3 | 231108T173507Z | Jonathan |
Python 2, 35 bytes
print"("+s[:3]+")",s[3:6]+"-"+s[6:]
Simply reduces the second solution of this answer by 2 bytes, since in Python 2 print would be a statement, not a function.
PowerShell, 46 bytes
"($($a[0..2])) $($a[3..5])-$($a[6..9])"-join''
The output is a little weird, if someone can suggest a fix to that it would be much appreciated!
Python, 36 bytes
slightly improved version of your f-string (see also Jonathan Allan's comment), wrapped in a function
print(f"({s[:3]}) {s[3:6]}-{s[6:]}")
Python, 37 bytes
without format strings
print("("+s[:3]+")",s[3:6]+"-"+s[6:])
uses that print inserts a space between arguments
Python, 39 bytes
C-style format string
print("(%s%s%s) %s%s%s-%s%s%s%s"%(*s,))
printing characters separately is slightly shorter than spiting string in 3 parts
Python 3, 35 bytes
print(f"({s:.3}) {s[3:6]}-{s[6:]}")
Uses the solution from the question but saves three bytes:
- removes a redundant
:in the final slices[6::], and - uses the
precisionspecifier (.) of theformat_spec(the bit after the:in{...:...}) which is overloaded for string types to give a prefix so{s[0:3]}->{s[:3]}->{s:.3}