A Palindrome word is that which is same even when read backwards. For ex. – Bob Find all Palindrome words in given sentences.
📌 Challenge Details and Links
ExcelBI Excel Challenge Number: 275
Challenge Difficulty: ⭐️
📥Download Sample File
📥Link to the solutions on LinkedIn
Solving the challenge of Find Palindrome Words in Text with Power Query
Power Query solution 1 for Find Palindrome Words in Text, proposed by Bo Rydobon 🇹🇭:
let
Source = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content],
Ans = Table.TransformRows(
Source,
each Text.Proper(
Text.Combine(
List.Select(
Text.SplitAny(Text.Lower([Sentences]), ", "),
each _ = Text.Reverse(_) and Text.Length(_) > 1
),
", "
)
)
)
in
Ans
Power Query solution 2 for Find Palindrome Words in Text, proposed by Zoran Milokanović:
let
Source = Excel.CurrentWorkbook(){[Name = "Input"]}[Content],
S = Table.TransformRows(
Source,
each Text.Combine(
List.Transform(
List.Select(
Text.Split(Text.Select(Text.Lower([Sentences]), {"a" .. "z", " "}), " "),
(e) =>
let
l = Text.ToList(e)
in
l = List.Reverse(l) and List.Count(l) > 1
),
Text.Proper
),
", "
)
)
in
S
Power Query solution 3 for Find Palindrome Words in Text, proposed by Rick de Groot:
let
Source = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content],
Palindromes = Table.TransformColumns(
Source,
{
{
"Sentences",
each [
a = Text.SplitAny(_, ", "),
b = List.Select(
a,
each Text.Length(_)
> 1 and Comparer.Equals(Comparer.OrdinalIgnoreCase, _, Text.Reverse(_))
),
c = Text.Combine(b, ", "),
d = Text.Proper(c)
][d]
}
}
)
in
Palindromes
Power Query solution 4 for Find Palindrome Words in Text, proposed by Alejandro Simón 🇵🇦 🇪🇸:
let
Source = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content],
Sol = Table.AddColumn(
Source,
"Answer",
each
let
a = Text.SplitAny(Text.Lower([Sentences]), ", "),
b = List.Select(a, each _ = Text.Reverse(_)),
c = List.Transform(b, each Text.Proper(_)),
d = Text.Combine(List.Select(c, each Text.Length(_) > 1), ", ")
in
d
)[[Answer]]
in
Sol
Power Query solution 5 for Find Palindrome Words in Text, proposed by Luan Rodrigues:
let
Fonte = Tabela1,
res = Table.AddColumn(
Fonte,
"Personalizar",
each Text.Combine(
List.Transform(
List.Select(
Text.Split(Text.Remove([Sentences], ","), " "),
(x) => Text.Proper(x) = Text.Proper(Text.Reverse(x)) and Text.Length(x) <> 1
),
Text.Proper
),
", "
)
)
in
res
Power Query solution 6 for Find Palindrome Words in Text, proposed by Brian Julius:
let
Source = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content],
AddAnswer = Table.AddColumn(
Source,
"Answer",
each [
a = Text.Lower(Text.Remove([Sentences], ",")),
b = Text.Split(a, " "),
c = List.Transform(b, each if _ = Text.Reverse(_) then Text.Proper(_) else ""),
d = List.Transform(c, each if Text.Length(_) > 1 then _ else null),
e = Text.Combine(d, ", ")
][e]
)
in
AddAnswer
Power Query solution 7 for Find Palindrome Words in Text, proposed by Rafael González B.:
let
Source = Excel.CurrentWorkbook(){0}[Content],
Sol = Table.AddColumn(
Source,
"Answer Expected",
each
let
a = Text.Replace(Text.Lower([Sentences]), ",", ""),
b = Text.Split(a, " "),
c = List.Select(b, each _ = Text.Reverse(_)),
d = List.Select(c, each Text.Length(_) > 1),
e = Text.Combine(d, ", "),
f = Text.Proper(e)
in
f
)[[Answer Expected]]
in
Sol
Power Query solution 8 for Find Palindrome Words in Text, proposed by Szabolcs Phraner:
let
Source = Excel.CurrentWorkbook(){[Name = "Sentences"]}[Content],
// Custom Function, that returns True for Palindrome words
FN_Palindrome = (Input) =>
let
//Create a list of each individual character, ensuring comparability with text.lower
CharList = List.Transform(Text.ToList(Input), Text.Lower),
// Reverse the List of Characters
Reverse = List.Reverse(CharList),
// Checks if the specific word is Palindrome
Condition = CharList = Reverse and List.Count(CharList) > 1
in
Condition,
Panidrome_Words = Table.AddColumn(
Source,
"Palindrome",
each
let
//Split Text String to List of words
WordList = Text.Split([Sentences], " "),
// Use custom function to select Palindrome words
SelectPalindrome = List.Select(WordList, FN_Palindrome)
//Combine List of Palindrome Words to one Text String
in Text.Combine(SelectPalindrome, ", "),
type text
)
in
Panidrome_Words
Power Query solution 9 for Find Palindrome Words in Text, proposed by Kalyan Kumar Reddy Kethireddy:
let
Source = Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText(#"Palindrome Words", BinaryEncoding.Base64),
Compression.Deflate
)
),
let
_t = ((type nullable text) meta [Serialized.Text = true])
in
type table [Sentences = _t]
),
#"Changed Type" = Table.TransformColumnTypes(Source, {{"Sentences", type text}}),
Result = Table.AddColumn(
#"Changed Type",
"Expected",
each [
a = Text.SplitAny([Sentences], ", "),
b = List.Select(a, each Text.Length(_) > 1),
c = List.Transform(b, each Text.Reverse(_)),
d = Text.Proper(Text.Combine(List.Intersect({b, c}, Comparer.OrdinalIgnoreCase), ", "))
][d]
)
in
Result
Solving the challenge of Find Palindrome Words in Text with Excel
Excel solution 1 for Find Palindrome Words in Text, proposed by Bo Rydobon 🇹🇭:
=PROPER(MAP(A2:A10,
LAMBDA(a,
TEXTJOIN(", ",
,
MAP(TEXTSPLIT(
a,
",",
" ",
1
),
LAMBDA(b,
REPT(b,
(LEN(
b
)>1)*(b=CONCAT(
MID(
b,
20-SEQUENCE(
19
),
1
)
)))))))))
Excel solution 2 for Find Palindrome Words in Text, proposed by Rick Rothstein:
=LET(f,LAMBDA(x,CONCAT(MID(x,SEQUENCE(LEN(x),,LEN(x),-1),1))=x),s,TEXTSPLIT(TEXTJOIN(" / ",,A2:A10),,{" ",","}),BYROW(TEXTSPLIT(TEXTJOIN(" ",,TOCOL(IF(MAP(s,LAMBDA(z,f(z))),IF((LEN(s)>1)+(s="/"),s,1/0),1/0),3)),,"/",1),LAMBDA(z,SUBSTITUTE(TRIM(PROPER(z))," ",", "))))
Excel solution 3 for Find Palindrome Words in Text, proposed by John V.:
=MAP(
A2:A10,
LAMBDA(
s,
TEXTJOIN(
", ",
,
PROPER(
MAP(
TEXTSPLIT(
s,
{", ";" "}
),
LAMBDA(
x,
REPT(
x,
AND(
LEN(
x
)>1,
CONCAT(
MID(
x,
31-ROW(
1:30
),
1
)
)=x
)
)
)
)
)
)
)
)
Excel solution 4 for Find Palindrome Words in Text, proposed by محمد حلمي:
=MAP(A2:A10,LAMBDA(a,LET(
i,TEXTSPLIT(a,{", "," "}),PROPER(TEXTJOIN(", ",,
REPT(i,MAP(i,LAMBDA(r,CONCAT(
MID(r,51-ROW(1:50),1))=r))*LEN(i)>1))))))
=MAP(A2:A10,LAMBDA(a,LET(
i,TEXTSPLIT(a,,{", "," "}),
PROPER(ARRAYTOTEXT(FILTER(i,
IFERROR(SEARCH(i,
CONCAT(MID(i,51-SEQUENCE(,50),1)))*
(LEN(i)>1)*(RIGHT(i)=LEFT(i)),),""))))))
Excel solution 5 for Find Palindrome Words in Text, proposed by 🇰🇷 Taeyong Shin:
=MAP(PROPER(A2:A10),LAMBDA(m,LET(t,TEXTSPLIT(m,," "),ARRAYTOTEXT(FILTER(t,(t=REDUCE("",SEQUENCE(MAX(LEN(t))), LAMBDA(a,n,MID(t,n,1)&a)))*(LEN(t)>1),"")))))
Excel solution 6 for Find Palindrome Words in Text, proposed by Kris Jaganah:
=MAP(A2:A10,
LAMBDA(y,
LET(a,
TEXTSPLIT(
SUBSTITUTE(
y,
",",
""
),
,
" "
),
ARRAYTOTEXT(FILTER(a,
MAP(a,
LAMBDA(x,
(LEN(
x
)>1)*(CONCAT(
MID(
x,
SEQUENCE(
LEN(
x
),
,
LEN(
x
),
-1
),
1
)
)=x))),
"")))))
Excel solution 7 for Find Palindrome Words in Text, proposed by Timothée BLIOT:
=MAP(
A2:A10,
LAMBDA(
z,
LET(
T,
TEXTSPLIT(
z,
{" ",
", "}
),
B,
MAP(
T,
LAMBDA(
x,
LET(
A,
LEN(
x
),
IF(
A>1,
CONCAT(
MID(
x,
SEQUENCE(
A
),
1
)
)=CONCAT(
MID(
x,
SEQUENCE(
A,
,
A,
-1
),
1
)
)
)
)
)
),
PROPER(
ARRAYTOTEXT(
FILTER(
T,
B,
""
)
)
)
)
)
)
Excel solution 8 for Find Palindrome Words in Text, proposed by Hussein SATOUR:
=MAP(
A2:A10,
LAMBDA(
x,
TEXTJOIN(
", ",
,
MAP(
TEXTSPLIT(
PROPER(
SUBSTITUTE(
x,
",",
""
)
),
" "
),
LAMBDA(
y,
IF(
AND(
LEN(
y
) > 1,
LOWER(
y
) = LOWER(
CONCAT(
MID(
y,
SEQUENCE(
LEN(
y
),
,
LEN(
y
),
-1
),
1
)
)
)
),
y,
""
)
)
)
)
)
)
Excel solution 9 for Find Palindrome Words in Text, proposed by Oscar Mendez Roca Farell:
=MAP(
A2:A10,
LAMBDA(
a,
LET(
_w,
TEXTSPLIT(
REDUCE(
"",
SEQUENCE(
99
),
LAMBDA(
i,
x,
MID(
a,
x,
1
)&i
)
),
",",
" "
),
_l,
LEN(
_w
),
IFERROR(
ARRAYTOTEXT(
PROPER(
TOCOL(
IF(
_l>2,
MID(
a,
FIND(
_w,
a
),
_l
),
NA()
),
2
)
)
),
""
)
)
)
)
Excel solution 10 for Find Palindrome Words in Text, proposed by Duy Tùng:
=MAP(A2:A10,LAMBDA(v,LET(a,TEXTSPLIT(v,,{","," "},1),ARRAYTOTEXT(PROPER(FILTER(a,MAP(a,LAMBDA(x,CONCAT(MID(x,LEN(x)+1-SEQUENCE(LEN(x)),1))=x))*LEN(a)>2,""))))))
Excel solution 11 for Find Palindrome Words in Text, proposed by Sunny Baggu:
=MAP(
A2:A10,
LAMBDA(a,
LET(
_ts, TEXTSPLIT(a, , {", ", " "}),
_trev, DROP(
REDUCE(
"Happy Teachers day Vijay Sir🌼",
_ts,
LAMBDA(a, v, VSTACK(a, CONCAT(MID(v, LEN(v) + 1 - SEQUENCE(LEN(v)), 1))))
),
1
),
ARRAYTOTEXT(PROPER(FILTER(_ts, (_ts = _trev) * (LEN(_ts) > 1), "")))
)
)
)
Excel solution 12 for Find Palindrome Words in Text, proposed by LEONARD OCHEA 🇷🇴:
=BYROW(
A2:A10,
LAMBDA(
a,
LET(
m,
TEXTSPLIT(
SUBSTITUTE(
a,
",",
""
),
" "
),
TEXTJOIN(
", ",
,
IFERROR(
PROPER(
FILTER(
m,
MAP(
m,
LAMBDA(
b,
LET(
l,
LEN(
b
),
s,
SEQUENCE(
l
),
P,
LAMBDA(
x,
AND(
l>1,
MID(
x,
s,
1
)=MID(
x,
l-s+1,
1
)
)
),
P(
b
)
)
)
)
)
),
""
)
)
)
)
)
Excel solution 13 for Find Palindrome Words in Text, proposed by Abdallah Ally:
=MAP(
A2:A10,
LAMBDA(
v,
REDUCE(
"",
TEXTSPLIT(
v,
{" ",
", "}
),
LAMBDA(
x,
y,
IF(
AND(
LEN(
y
)>1,
LOWER(
y
)=LOWER(
CONCAT(
MID(
y,
SEQUENCE(
LEN(
y
),
,
LEN(
y
),
-1
),
1
)
)
)
),
TEXTJOIN(
", ",
TRUE,
PROPER(
x
),
PROPER(
y
)
),
x
)
)
)
)
)
Excel solution 14 for Find Palindrome Words in Text, proposed by Anshu Bantra:
=MAP(
A1:A10,
LAMBDA(
lst,
LET(
lst,
TEXTSPLIT(
LOWER(
lst
),
" "
),
tsl,
MAP(
lst,
LAMBDA(
l,
TEXTJOIN(
"",
,
MID(
l,
SEQUENCE(
LEN(
l
),
,
LEN(
l
),
-1
),
1
)
)
)
),
IFERROR(
TEXTJOIN(
", ",
,
FILTER(
tsl,
TEXTSPLIT(
lst,
" "
) = TEXTSPLIT(
tsl,
" "
)
)
),
""
)
)
)
)
Excel solution 15 for Find Palindrome Words in Text, proposed by Asheesh Pahwa:
=a,0),FILTER(x,b,"")))),BYROW(g,
LAMBDA (z,TEXTJOIN(", ",TRUE, PROPER(z)))))
Excel solution 16 for Find Palindrome Words in Text, proposed by Charles Roldan:
=LET(
_Map,
LAMBDA(
f,
LAMBDA(
x,
MAP(
x,
f
)
)
),
_Fil,
LAMBDA(
f,
LAMBDA(
x,
FILTER(
x,
f(
x
),
""
)
)
),
_Sym,
LAMBDA(u,
LAMBDA(x,
IF(LEN(
x
) < 2,
TRUE,
IF(LEFT(
x
) = RIGHT(
x
),
u(
u
)(MID(
x,
2,
LEN(
x
) - 2
)))))),
_Pal,
LAMBDA(
x,
IF(
LEN(
x
) < 2,
FALSE,
_Sym(
_Sym
)(
x
)
)
),
_Spl,
LAMBDA(
x,
TEXTSPLIT(
x,
{" ",
", "}
)
),
_Map(LAMBDA(x,
ARRAYTOTEXT(PROPER(_Fil(
_Map(
_Pal
)
)(_Spl(
LOWER(
x
)
))))))
)(A2:A10)
Excel solution 17 for Find Palindrome Words in Text, proposed by Julien Lacaze:
=LET(data,
A2:A10,
isPalindrome,
LAMBDA(text,
MAP(text,
LAMBDA(t,
LET(a,
CONCAT(
MID(
t,
SEQUENCE(
LEN(
t
),
,
LEN(
t
),
-1
),
1
)
),
--(a=t))))),
IFERROR(PROPER(MAP(data,
LAMBDA(d,
LET(s,
TEXTSPLIT(
SUBSTITUTE(
d,
",",
""
),
" "
),
TEXTJOIN(", ",
,
FILTER(s,
isPalindrome(
s
)*(LEN(
s
)>1))))))),
""))
Excel solution 18 for Find Palindrome Words in Text, proposed by Pieter de Bruijn:
=MAP(SUBSTITUTE(A2:A10,",",""),LAMBDA(a,LET(t,TEXTSPLIT(a,," "),c,COUNTA(t),r,CONCAT(MID(a,99-ROW(1:98),1)),TEXTJOIN(", ",1,(IF((LEN(t)>1)*(t=INDEX(TEXTSPLIT(r," "),SEQUENCE(c,,c,-1))),PROPER(t),""))))))
Excel solution 19 for Find Palindrome Words in Text, proposed by Giorgi Goderdzishvili:
=MAP(A2:A10,LAMBDA(y,LET(
snt, SUBSTITUTE(y,",",""),
spl, TEXTSPLIT(snt," "),
mp, MAP(spl,LAMBDA(x,
LET(ln, LEN(x),
sq, SEQUENCE(,ln),
chck, SUM(--(MID(x,sq,1)=MID(x,SEQUENCE(,ln,ln,-1),1)))=ln,
chck))),
fn,TEXTJOIN(", ",,FILTER(PROPER(spl),mp*(spl<>"a"))),
IFERROR(fn,""))))
Excel solution 20 for Find Palindrome Words in Text, proposed by Daniel Garzia:
=MAP(A2:A10,
LAMBDA(r,
LET(t,
TEXTSPLIT(
r,
,
{" ",
", "}
),
IFERROR(TEXTJOIN(", ",
,
PROPER(IF((LEN(
t
)>1)*MAP(
t,
LAMBDA(
x,
x=CONCAT(
MID(
x,
99-ROW(
1:98
),
1
)
)
)
),
t,
""))),
""))))
Excel solution 21 for Find Palindrome Words in Text, proposed by samir tobeil:
=MAP(A2:A10,LAMBDA(x,LET(s,TEXTSPLIT(x,{" ",","},,1),
t,MAP(s,LAMBDA(p,LET(f,LEN(p),CONCAT(MID(p,SEQUENCE(f,,f,-1),1))))),
e,EXACT(LOWER(s),LOWER(t)),
TEXTJOIN(",",,IF(e*(LEN(s)>1),PROPER(s),"")))))
Excel solution 22 for Find Palindrome Words in Text, proposed by Md Ismail Hosen:
=LAMBDA(
Sentences,
LET(
ISPALINDROME,
LAMBDA(
NumberOrText,
[ConsiderCase],
LET(
_CorrectCaseSensitivity,
IF(
ISOMITTED(
ConsiderCase
),
TRUE,
ConsiderCase
),
_fxForOneItem,
LAMBDA(
OneTextOrNumber,
LET(
_Seq,
SEQUENCE(
LEN(
OneTextOrNumber
)
),
_Chars,
MID(
OneTextOrNumber,
_Seq,
1
),
_ReverseChars,
MID(
OneTextOrNumber,
SORT(
_Seq,
,
-1
),
1
),
AND(
_Chars = _ReverseChars
)
)
),
_CorrectTextForCasehaviour,
IF(
_CorrectCaseSensitivity,
NumberOrText,
LOWER(
NumberOrText
)
),
_Result,
MAP(
_CorrectTextForCasehaviour,
_fxForOneItem
),
_Result
)
),
fxOne,
LAMBDA(
Sentence,
LET(
Words,
TEXTSPLIT(
Sentence,
{" ",
", "}
),
Mask,
MAP(
Words,
LAMBDA(
a,
AND(
ISPALINDROME(
a
),
LEN(
a
) > 1
)
)
),
PalindromicWordsOnly,
IFERROR(
TEXTJOIN(
", ",
TRUE,
FILTER(
Words,
Mask
)
),
""
),
PROPER(
PalindromicWordsOnly
)
)
),
Result,
MAP(
Sentences,
fxOne
),
Result
)
)(A2:A10)
Excel solution 23 for Find Palindrome Words in Text, proposed by Mungunbayar Bat-Ochir:
=LET(
arr;
IFERROR(
TEXTSPLIT(
TEXTJOIN(
CHAR(
30
);
;
SUBSTITUTE(
A2:A10;
",";
""
)
);
" ";
CHAR(
30
)
);
""
);
Func;
LAMBDA(
input;
SWITCH(
TRUE;
OR(
LEN(
input
)=1;
input=""
);
"";
input=CONCAT(
MID(
input;
SEQUENCE(
LEN(
input
);
;
LEN(
input
);
-1
);
1
)
);
input;
""
)
);
arr_2;
MAKEARRAY(
ROWS(
arr
);
COLUMNS(
arr
);
LAMBDA(
row;
col;
Func(
INDEX(
arr;
row;
col
)
)
)
);
result;
PROPER(
BYROW(
arr_2;
LAMBDA(
row;
TEXTJOIN(
", ";
TRUE;
row
)
)
)
);
result
)
Excel solution 24 for Find Palindrome Words in Text, proposed by Hazem Hassan:
=LET(
a;
TEXTSPLIT(
CONCAT(
A2:A10&"*"
);
{" ";
","};
"*";
1
);
b;
IF(
LEN(
a
)>1;
a;
""
);
PROPER(
BYROW(
IFERROR(
IFS(
MAP(
a;
LAMBDA(
x;
CONCAT(
MID(
x;
SORT(
SEQUENCE(
LEN(
x
)
);
;
-1
& );
1
)
)
)
)=b;
b
);
""
);
LAMBDA(
x;
TEXTJOIN(
",";
1;
x
)
)
)
)
)
Excel solution 25 for Find Palindrome Words in Text, proposed by Miguel Angel Franco García:
=LET(
a;
DIVIDIRTEXTO(
MINUSC(
UNIRCADENAS(
" ";
VERDADERO;
SI.ERROR(
DIVIDIRTEXTO(
A2;
" ";
","
);
""
)
)
);
" "
);
b;
DIVIDIRTEXTO(
MINUSC(
UNIRCADENAS(
"";
VERDADERO;
SUSTITUIR(
EXTRAE(
A2;
SECUENCIA(
;
LARGO(
A2
);
LARGO(
A2
);
-1
);
1
);
",";
""
)
)
);
" "
);
resul;
INDICE(
b;
;
ENFILA(
COINCIDIR(
a;
b;
0
);
3
)
);
NOMPROPIO(
SI.ERROR(
UNIRCADENAS(
",";
VERDADERO;
ENFILA(
SI(
LARGO(
resul
)>1;
resul;
NOD()
);
3
)
);
""
)
)
)
Excel solution 26 for Find Palindrome Words in Text, proposed by Kriddakorn Pongthanisorn:
=BYROW(
A2:A10,
LAMBDA(
_sent,
LET(
_raw,
_sent,
_ini,
TRANSPOSE(
ArrayFormula(
IFERROR(
REGEXEXTRACT(
SPLIT(
LOWER(
_raw
),
" ",
1
),
"[a-z]+[a-z]+"
),
)
)
),
_rev,
BYROW(
_ini,
LAMBDA(
_ini,
ARRAYFORMULA(
IFERROR(
CONCATENATE(
MID(
_ini,
SEQUENCE(
1,
LEN(
_ini
),
LEN(
_ini
),
-1
),
1
)
),
)
)
)
),
_output,
TEXTJOIN(
", ",
1,
MAP(
_ini,
_rev,
LAMBDA(
_ini,
_rev,
PROPER(
IF(
AND(
_ini=_rev,
_ini<>""
),
_ini,
)
)
)
)
),
_output
)
)
)
Excel solution 27 for Find Palindrome Words in Text, proposed by Ali Hassan, CPA:
=BYROW(A2:A10,LAMBDA(row,TEXTJOIN(", ",TRUE,MAP(TEXTSPLIT(SUBSTITUTE(row,",","")," "),LAMBDA(cell,LET(word,cell,array,MAKEARRAY(LEN(word),1,LAMBDA(r,c,MID(word,r,1))),reverse,CHOOSECOLS(SORT(HSTACK(array,SEQUENCE(ROWS(array),,0)),2,-1),1),IF(AND(TEXTJOIN("",,array)=TEXTJOIN("",,reverse),ROWS(array)>1),PROPER(word),"")))))))
Excel solution 28 for Find Palindrome Words in Text, proposed by Tom Hinkle:
=LAMBDA(
Palintext,
IF(
LEN(
Palintext
)<2,
0,
IF(
LEFT(
Palintext
)=RIGHT(
Palintext
),
Palindrome(
MID(
Palintext,
2,
LEN(
Palintext
)-2
)
),
1
)
)
)
it will return 0 if it's a palindrome,
1 if not. Could make it do actual text,
but I have to get to work :)
Solving the challenge of Find Palindrome Words in Text with Python in Excel
Python in Excel solution 1 for Find Palindrome Words in Text, proposed by Bo Rydobon 🇹🇭:
Python Regex
import re
[ ', '.join([b.title() for b in re.split(',| ',a.lower()) if b[::-1]==b and len(b)>1]) for a in xl("A2:A10")[0].values]
Python in Excel solution 2 for Find Palindrome Words in Text, proposed by Bo Rydobon 🇹🇭:
Python
[", ".join([b.title() for b in a.lower().replace(',','').split(" ") if b[::-1]==b and len(b)>1]) for a in xl("A2:A10")[0].values]
Python in Excel solution 3 for Find Palindrome Words in Text, proposed by 🇰🇷 Taeyong Shin:
Python
nd = xl("A2:A10")[0].values
[', '.join(w for w in s.lower().split()
if w == w[::-1] and len(w) > 1).title() for s in nd]
df = xl("A2:A10")
def find_palindromes(sentence):
return ', '.join(w.title() for w in sentence.lower().split() if w == w[::-1] and len(w) > 1)
df = df.applymap(find_palindromes)
Python in Excel solution 4 for Find Palindrome Words in Text, proposed by Diarmuid Early:
[", ".join([wrd.capitalize() for wrd in sent[0].lower().replace(",","").split() if (wrd == wrd[::-1] and len(wrd) > 1)]) for sent in xl("A2:A10").values]
Highlights:
* ", ".join(list) is like Excel TEXTJOIN(", ",,list)
* wrd.capitalize() is like Excel PROPER()
I'm saving all my Python solutions to these challenges here if anyone wants to explore:
http://bit.ly/PythonLearningFolder
Python in Excel solution 5 for Find Palindrome Words in Text, proposed by Md Ismail Hosen:
def PalindromeWords(Sentence):
return ", ".join(PalindromeWords)
df=xl("A1:A10", headers=True)
df["Sentences"].apply(PalindromeWords).values
Solving the challenge of Find Palindrome Words in Text with R
R solution 1 for Find Palindrome Words in Text, proposed by Konrad Gryczan, PhD:
library(tidyverse)
library(readxl)
library(stringi)
input = read_excel("Palindrome Words.xlsx") %>% select(1)
find_palindromes <- function(sentence) {
return(palindromes)
}
result = input %>%
rowwise() %>%
mutate(Palindromes = list(find_palindromes(Sentences))) %>%
ungroup() %>%
mutate(Palindromes = map_chr(.x = Palindromes, .f = ~ paste(str_to_sentence(.x), collapse = ", ")))
Solving the challenge of Find Palindrome Words in Text with Excel VBA
Excel VBA solution 1 for Find Palindrome Words in Text, proposed by Nicolas Micot:
VBA solution:
Function f_getPalindrome(texte As String) As String
Dim resultat As String
texte = LCase(Replace(texte, ",", ""))
tableau = Split(texte, " ")
For i = 0 To UBound(tableau, 1)
If tableau(i) = StrReverse(tableau(i)) And Len(tableau(i)) > 1 Then
If Not resultat = "" Then resultat = resultat & ", "
resultat = resultat & UCase(Left(tableau(i), 1)) & Mid(tableau(i), 2)
End If
Next i
f_getPalindrome = resultat
End Function
&
