| Bytes | Lang | Time | Link |
|---|---|---|---|
| 101 | R | 240602T212622Z | int 21h |
| 095 | R | 240603T121519Z | pajonk |
| 061 | Arturo | 240603T173705Z | chunes |
| 025 | SM83 | 240603T022428Z | NoLonger |
| 016 | Uiua SBCS | 240603T013948Z | chunes |
| 004 | Vyxal | 240130T121517Z | lyxal |
| 084 | Java JDK | 170630T083650Z | Olivier |
| 088 | Noulith | 231128T144851Z | bigyihsu |
| 184 | Go | 231128T142451Z | bigyihsu |
| 143 | Rust | 231128T140838Z | cg909 |
| 098 | Python 3 | 170628T212840Z | Luke Saw |
| 011 | Jelly | 231128T014306Z | Unrelate |
| 081 | JavaScript ES6 | 170628T222127Z | Shaggy |
| nan | GNU sed | 171203T162152Z | Jordan |
| 018 | Charcoal | 171201T205646Z | Neil |
| 110 | PHP | 170705T112336Z | Xanderha |
| nan | Perl | 170703T182044Z | Weizel |
| 040 | Perl 5 | 170704T094108Z | Dada |
| 092 | Perl | 170703T203434Z | jmatix |
| 080 | Ruby | 170630T173155Z | Alex |
| 213 | Google Sheets | 170630T155257Z | Engineer |
| 104 | Common Lisp | 170630T045923Z | Renzo |
| 161 | Java 8 | 170629T073600Z | Kevin Cr |
| 199 | Swift 3.0 | 170630T081749Z | A. Pooja |
| 181 | PHP | 170630T034424Z | kip |
| 049 | q/kdb+ | 170629T211103Z | mkst |
| 100 | Python 2 | 170629T191205Z | Erik |
| 024 | V | 170628T211813Z | DJMcMayh |
| 081 | Haskell | 170628T231940Z | Julian W |
| 014 | 05AB1E | 170628T211849Z | Riley |
| 071 | Retina | 170628T231321Z | Neil |
| 033 | Charcoal | 170629T101229Z | Charlie |
| 128 | SCALA | 170629T095343Z | V. Court |
| 066 | C gcc | 170629T005827Z | Dennis |
| 101 | C# .NET Core | 170629T062802Z | Charlie |
| 032 | Alice | 170629T052424Z | Nitrodon |
| 072 | Python 3 | 170629T042153Z | Dennis |
| 105 | Python 2 | 170629T030749Z | Chas Bro |
| 013 | Jelly | 170628T213350Z | Dennis |
| 124 | Python 3 | 170628T213622Z | Chris |
| 018 | MATL | 170628T213936Z | Luis Men |
| 103 | C | 170628T212228Z | Steadybo |
| 114 | Python 2 | 170628T213124Z | hyper-ne |
R, 106 101 bytes
-5 bytes thanks to Giuseppe
\(s,`+`=casefold,l=+gsub(" ","",s)){for(i in el(gregexpr("[A-Z]",s)))substr(l,i,i)=substr(l,i,i)+1;l}
Pretty close to my target <100 bytes:)
In this approach some code is reduced by using a single function casefold (with a short alias) instead of the usual tolower/toupper couple.
An attempt to remove the curly braces did not improve the byte count.
R, 96 95 bytes
\(s,p=utf8ToInt(s)){p[U]=p[U<-p%%65<26]+32
r=p[p>32]
r[V]=r[V<-U[seq(r)]&r>96]-32
intToUtf8(r)}
Alternative
\(s,`?`=utf8ToInt,r=?tolower(s)){r=r[r>32]
r[V]=r[V<-(?s)[seq(r)]%%65<26&r>96]-32
intToUtf8(r)}
Based on int 21h -- Glory to Ukraine --'s R answer, but operates on character codes instead of strings.
Arturo, 61 bytes
$->s[i:0map--s` `'c[c(upper? s\[i])?[upper][lower]'i+1]|join]
Explanation
$->s[] ; a function taking a string s
i:0 ; assign zero to i
map ; map over...
--s` ` ; input without spaces...
'c[] ; ...assigning current char to c
c ; push c
(upper? s\[i])? ; is i'th character in (unmodified) input upper case?
[upper] ; then uppercase c
[lower] ; else lowercase it
'i+1 ; increment i
| ; then...
join ; join mapped letters to string
SM83, 25 bytes
Makes use of the fact that all the legit punctuation is less than @ and therefore has bit 6 turned off, so we can assume that if bit 6 is on it's a letter.
54 5D 1A 13 FE 20 28 FA 47 A6 CB 77 78 28 05 E6
20 CB AE B6 22 B7 20 EA C9
Disassembled:
f:
ld d,h // 54 // copy hl into de
ld e,l // 5D
l:
ld a,(de) // 1A // a = *(de++)
inc de // 13
cp a,' ' // FE 20 // if a == ' '
jr z,l // 28 FA // loop back
ld b,a // 47 // safeguard a
and (hl) // A6 // AND with *hl
bit 6,a // CB 77 // are both letters?
ld a,b // 78 // copy back
jr z,s // 28 05 // if so jump straight to store
and $20 // E6 20 // otherwise mask off all but 5th bit
res 5,(hl) // CB AE // and erase 5th bit of *hl
or (hl) // B6 // and or them together
s:
ld (hl+),a // 22 // *(hl++) = a
or a // B7 // cheap test for 0
jr nz,l // 20 EA // jump back if wasn't null
ret // C9 // return
Vyxal, 4 bytes
ȧ⇩$•
Helps to have a "with capitalisation of" built-in
Explained
ȧ⇩$•
ȧ # Remove whitespace from the input
⇩ # and lowercase it
$• # Transfer the capitalisation of the original input to the stripped input.
# The reason for `•` doing this is because on lists, `•` is mould. Therefore, the idea was that it "moulds" one string to the capitalization of the other
💎
Created with the help of Luminespire.
Java (JDK), 84 bytes
s->{int j=0,c;for(var k:s)if((c=k&95)>0)System.out.printf("%c",c^(s[j++]|~c/2)&32);}
Credits :
- Dennis for the bit twiddling as it's a good way to shorten the answer
- Fhuvi for trimming 12 bytes.
Noulith, 88 bytes
\s->(for(p<<-s.lower filter (!=' '))yield if(s[p[0]].is_upper)p[1].upper else p[1])join""
Go, 184 bytes
import(."strings";u"unicode")
func f(s string)string{S:=[]rune(ReplaceAll(ToLower(s)," ",""))
for i:=range s{if i<len(S)&&u.IsUpper(rune(s[i])){S[i]=u.ToUpper(S[i])}}
return string(S)}
Rust, 143 bytes
|s|str::to_lowercase(s).replace(' ',"").chars().zip(s.chars()).for_each(|(c,d)|print!("{}",if d.is_uppercase(){c.to_ascii_uppercase()}else{c}))
Ungolfed:
|input: &str|
input.to_lowercase() // create lowercase string
.replace(' ', "") // remove all spaces
.chars() // iterate over characters
.zip(input.chars()) // zip with input character iterator
.for_each(|(c, input_c)| // for each character in both strings:
print!("{}", // print the following:
if input_c.is_uppercase() { // if the input character is uppercase
c.to_ascii_uppercase() // `c` in uppercase
}
else { c } // else `c`
)
)
Python 3, 117 114 98 bytes
s=input()
i,*y=0,*s.replace(' ','').lower()
for c in y:print(end=[c,c.upper()]['@'<s[i]<'[']);i+=1
Edit: 3 bytes saved by UndoneStudios.
Edit: 14 bytes saved by Unrelated String.
This is pretty much my first code golf, so it's likely to be bad, minus help from comments below!
P.S. Yes, it's dumb that defining and incrementing i saves bytes over range(len(y)). Oh well.
Python 3, 85 bytes
lambda s:''.join([c,c.upper()]['@'<b<'[']for b,c in zip(s,s.replace(' ','').lower()))
This solution is entirely due to att; I'm keeping it separate because the strategy seems to me to have changed enough.
Jelly, 11 bytes
ŒlðḲFŒuT}¦n
Just a restructuring of Dennis' original solution to avoid repeating Œl.
Œl Lowercase the input.
ð Make that the left argument to the following dyadic chain.
Ḳ Split on spaces,
F flatten out the splits,
Œu then uppercase that
T}¦ at the indices where
Œlð n the lowercase doesn't equal the original.
JavaScript (ES6), 94 91 85 84 81 bytes
s=>s.replace(r=/./g,c=>1/c?"":c[`to${r<s[x]&s[x++]<{}?"Upp":"Low"}erCase`](),x=0)
- 6 bytes saved with assistance from ETHproductions & Arnauld.
- 3 bytes saved thanks to l4m2
GNU sed, 67 + 1 = 68 bytes
+1 byte for -r flag.
:A
s/$/;/
:
s/([A-Z]);(.?)/;\l\1\u\2/
t
s/(\S);/;\1/
t
s/ ;//
/ /bA
Explanation
The algorithm is pretty simple:
Insert a cursor (
;) at the end of the line::A s/$/;/ :If the character before the cursor is an uppercase letter, lowercase it (
\l) and uppercase the character after the cursor (\u), moving the cursor to the left, and branch back to:s/([A-Z]);(.?)/;\l\1\u\2/ tOtherwise, if the character before the cursor is not a space, move the cursor to the left and branch back to
;:s/(\S);/;\1/ tOtherwise, if the cursor is preceded by a space, delete both:
s/ ;//Finally, if there are any spaces left, branch back to
:A:/ /bA
Charcoal, 18 bytes
⪫E⪫⪪θ ω⎇№α§θκ↥ι↧ιω
Try it online! Link is to verbose version of code. Explanation:
θ Input string
⪪ Split on spaces
⪫ ω Join together
E Loop over each character
§θκ Get character from original string
№α Search uppercase letters
⎇ If true (nonzero)
↥ι Uppercase the current character
↧ι Else lowercase the current character
⪫ ω Join together
Implicitly print
The recent addition of StringMap shaves off a couple of bytes:
⭆⪫⪪θ ω⎇№α§θκ↥ι↧ι
⭆ is roughly equivalent to ⪫E...ω.
PHP, 110 bytes
$q=strtr($s=$argn,[' '=>'']);foreach(str_split($s)as$k=>$v)echo$v<lcfirst($v)?ucfirst($q[$k]):lcfirst($q[$k]);
Breakdown
$q=strtr($s=$argn,[' '=>''])
We take our input ($argn) and store it in a smaller variable because we need it later, before stripping out all the spaces with strtr
foreach(str_split($s)as$k=>$v)
We then take our original string, split it into an array of characters, and loop through each of them.
echo$v<lcfirst($v)?ucfirst($q[$k]):lcfirst($q[$k])
We check to see if the current letter is uppercase (A is less than a probably because ASCII), and echo out the corresponding letter from the space-stripped string with the appropriate case.
Perl, 95 94 + 1 = 95 bytes
+1 byte penalty for -n
Save one byte by replace from s/\s//g to s/ //g
$s=$_;s/ //g;$_=lc($_);while(/(.)/gs){$p=$&;$p=uc($p)if(substr($s,$-[0],1)=~/[A-Z]/);print$p;}
Explanation:
Make copy of input string.
Remove all spaceses and transform string to lower case.
Then start loop over each letter. Test letter in same position in saved string for upper case. If it upper - make current letter captitalized. Print letter.
Note that perl need to be run with "-n" command line switch
Perl 5, 40 bytes
37 bytes of code + -F flag. (note that on old versions of Perl, you might need to add -an flags)
print$F[$i++]=~/[A-Z]/?uc:lc for/\S/g
Explanations:
Thanks to -F, @F contains a list of every characters of the input.
for/\S/g iterates over every non-space character of the input. We use $i to count at which iteration we are. If $F[$i++] is an uppercase character (/[A-Z]/), then we print the uppercase current character (uc), otherwise, we print it lowercase (lc). Note that uc and lc return their argument unchanged if it isn't a letter.
Previous version (less golfed: 47 bytes):
s/ //g;s%.%$_=$&;$F[$i++]=~/[A-Z]/?uc:lc%ge
Perl, 92 bytes
$p[$i++]=$-[0]while s/[A-Z]/lc($&)/e;s/\s//g;for$c(@p){substr($_,$c,1)=~tr[a-z][A-Z]};print;
Explanation:
$p[$i++]=$-[0]while s/[A-Z]/lc($&)/e; #get locations of caps into an array at the same time converting letters to lowercase
s/\s//g; #delete all spaces
for$c(@p){substr($_,$c,1)=~tr[a-z][A-Z]}; #convert lowercase letters to uppercase where uppercase letters were present
print; # print (of course) :)
Ruby, 80 bytes
->a{n=a.downcase.delete' '
n.size.times{|i|(?A..?Z)===a[i]&&n[i]=n[i].upcase}
n}
Google Sheets, 213 bytes
=ArrayFormula(JOIN("",IF(REGEXMATCH(MID(A1,ROW(OFFSET(A1,0,0,LEN(A1))),1),"[A-Z]"),MID(UPPER(SUBSTITUTE(A1," ","")),ROW(OFFSET(A1,0,0,LEN(A1))),1),MID(LOWER(SUBSTITUTE(A1," ","")),ROW(OFFSET(A1,0,0,LEN(A1))),1))))
Input is in cell A1 and the formula breaks down like this:
ArrayFormula()lets us evaluate each term ofROW()independentlyJOIN()concatenates all those independent results into a single stringIF(REGEXMATCH(),UPPER(),LOWER()is what makes it alternate using upper or lower case depending on what the case was at that position in the inputROW(OFFSET())returns an array of values1toA1.lengththat can be fed into theMID()function so we can evaluate each character in turn
Results of test cases: (It's easier to read if you click though to the larger version.)
Common Lisp, 104 bytes
(defun f(s)(map'string(lambda(x y)(if(upper-case-p x)(char-upcase y)(char-downcase y)))s(remove #\ s)))
Unusually short for the wordy Common Lisp!
Straightforward code:
(defun f (s) ; receive the string as parameter
(map 'string ; map the following function of two arguments
(lambda (x y) ; x from the original string, y from the string with removed spaces
(if (upper-case-p x) ; if x is uppercase
(char-upcase y) ; get y uppercase
(char-downcase y))) ; else get y lowercase
s
(remove #\ s)))
Java 8, 184 177 161 bytes
s->{String r="";for(int i=0,j=i,t,u;i<s.length;){t=s[i++];if(t>32){u=s[j++];r+=(char)(t<65|t>90&t<97|t>122?t:u>64&u<91?t&~32:u>96&u<123|u<33?t|32:t);}}return r;}
Can definitely be golfed some more..
- 16 bytes thanks to @OlivierGrégoire by taking the input as char[] instead of String.
Explanation:
s->{ // Method with char-array parameter and String return-type
String r=""; // Result-String
for(int i=0,j=i,t,u; // Some temp integers and indices
i<s.length;){ // Loop over the String
t=s[i++]; // Take the next character and save it in `t` (as integer)
// and raise index `i` by 1
if(t>32){ // If `t` is not a space:
u=s[j++]; // Take `u` and raise index `j` by 1
r+= // Append the result-String with:
(char) // Integer to char conversion of:
(t<65|t>90&t<97|t>122? // If `t` is not a letter:
t // Simply use `t` as is
:u>64&u<91? // Else if `u` is uppercase:
t&~32 // Take `t` as uppercase
:u>96&u<123|u<33? // Else if `u` is lowercase or a space:
t|32 // Take `t` as lowercase
: // Else:
t); // Take `t` as is
}
} // End of loop
return r; // Return result-String
} // End of method
Swift 3.0, 199 bytes
var s="AS Ff",i=[String](),p=[Int](),j=0;for c in s.characters{if c>="A"&&c<="Z"{p.append(j)};if c != " "{i.append(String(c).lowercased())};j=j+1};for c in p{i[c]=i[c].uppercased()};print(i.joined())
PHP, 181 bytes
I try get the minor numbers of bytes,this is my code:
<?php
$s=readline();
preg_match_all('/[A-Z]/',$s,$m,PREG_OFFSET_CAPTURE);
$s=strtolower(str_replace(' ','',$s));
while($d=each($m[0]))$s[$d[1][1]]=strtoupper($s[$d[1][1]]);
echo $s;
q/kdb+, 49 bytes
Solution:
{@[a;(&)#:[a:lower x except" "]#x in .Q.A;upper]}
Examples:
q){@[a;(&)#:[a:lower x except" "]#x in .Q.A;upper]}"Hi! Test!"
"Hi!tEst!"
q){@[a;(&)#:[a:lower x except" "]#x in .Q.A;upper]}"A Quick Brown Fox Jumped Over The Lazy Dog"
"AqUickbrOwnfoxJumpEdovertHelazYdog"
q){@[a;(&)#:[a:lower x except" "]#x in .Q.A;upper]}"testing TESTing TeStING testing testing TESTING"
"testingtESTIngteStInGTEstingtestingtestiNG"
q){@[a;(&)#:[a:lower x except" "]#x in .Q.A;upper]}"TESTING... ... ... success! EUREKA???!!! maybe, don't, NOOOOO"
"TESTING.........success!eureKA???!!!maybe,don't,nooooo"
q){@[a;(&)#:[a:lower x except" "]#x in .Q.A;upper]}"Enter PASSWORD ---------"
"Enterpassword---------"
q){@[a;(&)(#:[a:lower x except" "]#x)in .Q.A;upper]}"A a B b C c D d E e F f G g H h I i J j K k L l M m N n O o P p Q q R r S s T t U u V v W w X x Z z"
"AabbCcddEeffGghhIijjKkllMmnnOoppQqrrSsttUuvvWwxxZz"
q){@[a;(&)#:[a:lower x except" "]#x in .Q.A;upper]}" TEST"
"teST"
Explanation:
Find indices where input is uppercase and then apply function upper to those indices on a lowercase, space-removed version of the input string. Note that we cannot apply the function beyond the length of the string, so use take (#) to truncate the input string to length of the lowercase, space-removed version.
{@[a;where count[a:lower x except " "]#x in .Q.A;upper]} / ungolfed
{ } / lambda function
@[ ; ; ] / apply FUNC to VAR at INDICES: @[VAR;INDICES;FUNC]
upper / uppercase, upper["abc"] -> "ABC"
x in .Q.A / boolean list where input is in uppercase alphabet ABC..XYZ
# / take this many elements from list on the right (ie truncate)
count[ ] / returns length of the stuff inside the brackets, count["ABC"] -> 3
x except " " / remove " " from string
lower / lowercase, lower["ABC"] -> "abc"
a: / save in variable a
where / returns indices where true where[101b] -> 0 2
a / our lowercased, space-stripped input
Bonus:
After reading the answers, thought I'd try a solution where I iterate over the input, so far I've only managed a 53 byte solution:
{a{$[y in .Q.A;upper x;x]}'#:[a:lower x except" "]#x}
Python 2, 100 bytes
s=input()
print"".join([c.lower(),c.upper()][s[i].isupper()]for i,c in enumerate(s.replace(" ","")))
V, 24 bytes
ÄVuÓó
ejlDò/¥2lõ
vuk~òGd
These kind of challenges are exactly what V was made for. :)
Explanation:
Ä " Duplicate this line
Vu " Convert it to lowercase
Óó " Remove all spaces
e " Move to the end of this line
j " Move down a line (to the original)
l " Move one char to the right
D " And delete the end of this line
ò " Recursively:
/ " Search for:
õ " An uppercase character
¥2l " On line 2
" (This will break the loop when there are no uppercase characters left)
vu " Convert it to lowercase
k " Move up a line
~ " Convert this to uppercase also
ò " Endwhile
G " Move to the last line
d " And delete it
Haskell, 98 95 89 88 81 bytes
Thanks to @name, @nimi, @Zgarb, and @Laikoni for helping shave off 14 bytes total
import Data.Char
\s->zipWith(\p->last$toLower:[toUpper|isUpper p])s$filter(>' ')s
Ungolfed:
import Data.Char
\sentence -> zipWith (\oldChar newChar ->
if isUpper oldChar
then toUpper newChar
else toLower newChar)
sentence
(filter (/= ' ') sentence)
05AB1E, 15 14 bytes
-1 byte thanks to Emigna
ðKuvy¹Nè.lil}?
ðK # Remove spaces
u # Convert to uppercase
vy # For each character...
¹Nè # Get the character at the same index from the original input
.lil} # If it was a lowercase letter change this one to lowercase
? # Print without a newline
Retina, 77 71 bytes
.+
$&¶$&
T`L `l_`.+$
+`((.)*)[A-Z].*(¶(?<-2>.)*)
$1$3
.+¶
T`l `L_` .?
Try it online! Link includes test suite. Explanation: The first stage duplicates the line while the second stage lowercases the duplicate and deletes its spaces. The third stage then loops through each uppercase letter from right to left and attempts to place a space before the corresponding character on the second line. The first line is deleted and the spaces are used to uppercase the relevant characters of the result. Edit: Saved 6 bytes thanks to @Kobi.
Charcoal, 33 bytes
A⁰χFLθ¿⁼§θι A⁺¹χχ¿№α§θ⁻ιχ↥§θι↧§θι
As I still don't know how to pass a string with whitespaces as a single input parameter into Charcoal code, I just assign in the header the test string to the Charcoal variable that represents what would be the first input (θ):
AA Quick Brown Fox Jumped Over The Lazy Dogθ
So the code has the same number of bytes as if the string were passed as first input.
You can see here the verbose version of the code.
SCALA, 128 chars, 128 bytes
var l=s.toLowerCase().filter(x=>x!=32)
for(i<-0 to l.size-1){if(s(i).isUpper)l=l.substring(0,i)+l(i).toUpper+l.substring(i+1)}
l
Thanks for this challenge. Try it online!
C (gcc), 82 79 74 72 69 67 66 bytes
f(c){for(char*s=c,*p=c;c=*s++;c&&putchar(c^(*p++|~c/2)&32))c&=95;}
C# (.NET Core), 108 101 bytes
using System.Linq;s=>s.Replace(" ","").Select((c,i)=>s[i]>64&s[i]<91?char.ToUpper(c):char.ToLower(c))
- 7 bytes saved after realizing that the
charclass has staticToUpper()andToLower()methods.
Alice, 32 bytes
/..- ~l+u~mSloy
\ia''-y.'Qa.+a@/
Explanation
This is a standard template for programs that work entirely in ordinal mode. Unwrapped, the program is as follows:
i.' -l.uQm.lay.a-'~y+'~aS+o@
i take input as string
. duplicate
' - remove spaces from copy
l.u create all-lowercase and all-uppercase versions
Q reverse stack, so original string is on top
m truncate original string to length of spaces-removed string
.lay convert everything except uppercase characters to \n
.a-'~y convert everything except \n (i.e., convert uppercase characters) to ~
+ superimpose with lowercase string
\n becomes the corresponding lowercase character, and ~ remains as is
'~aS convert ~ to \n
+ superimpose with uppercase string
lowercase in existing string stays as is because it has a higher code point
\n becomes corresponding uppercase character
o output
@ terminate
Python 3, 78 75 72 bytes
s=input()
for c in s:s=s[c>' '!=print(end=(c+c).title()[s<'@'or'['<s]):]
Thanks to @xnor for golfing off 6 bytes!
Python 2, 106 105 bytes
s=input()
print''.join(map(lambda(c,u):[c.lower,c.upper][u](),zip(s.replace(' ',''),map(str.isupper,s))))
Edit: save one byte via print ''.join => print''.join.
Lambda form, 99 bytes
lambda s:''.join(map(lambda(c,u):[c.lower,c.upper][u](),zip(s.replace(' ',''),map(str.isupper,s))))
Jelly, 14 13 bytes
nŒlTɓḲFŒlŒuṛ¦
How it works
nŒlTɓḲFŒlŒuṛ¦ Main link. Argument: s (string)
Œl Convert s to lowercase.
n Perform character-wise "not equal" comparison.
T Get the indices of all truthy elements, i.e., the indices of all
uppercase letters in s. Let's call the resulting array J.
ɓ Begin a dyadic chain with left argument s and right argument J.
ḲF Split s at spaces and flatten, removing the spaces.
Œl Convert s to lowercase.
¦ Sparse application:
Œu Convert s to uppercase.
ṛ Take the resulting items of the uppercased string at all indices
in J, the items of the lowercased string at all others.
Python 3, 125, 124 bytes
lambda s:''.join(c.upper()if i in(s.find(q)for q in s if q.isupper())else c for i,c in enumerate(s.replace(' ','').lower()))
C, 103 bytes
i,j,c;f(char*s){for(i=j=0;c=tolower(s[j++]);)c-32&&putchar(c-32*(s[i]>64&&s[i]<91&&c>96&&c<123))&&++i;}
Python 2, 114 bytes
x=input()
X=x.replace(' ','')
print''.join([X[i].upper()if x[i].isupper()else X[i].lower()for i in range(len(X))])
Equivalently:
Python 2, 114 bytes
lambda x:''.join([[str.lower,str.upper][x[i].isupper()](x.replace(' ','')[i])for i in range(len(x)-x.count(' '))])
