операционная система Windows
Python (3.8)
Здравствуйте. Мне нужно было сделать программу(на С++), когда вводишь слова, выводит слова, которые начинаются и заканчиваются на одну и ту же букву. А теперь нужно перевести ее на питон, кто то может помочь?
Код на С++
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
string s;
cout << "Input words:" << endl;
getline(cin, s);
stringstream strm(s);
cout << "Your words:" << endl;
int wcount{ 0 };
for (string i; strm >> i
{
int lenght = i.length() - 1;
if (i[0] == i[lenght]) {
cout << i << endl;
wcount++;
}
else if ((i[lenght] == '!') || (i[lenght] == '?') || (i[lenght] == '.'))
{
i.erase(lenght--);
if (i[0] == i[lenght]) {
cout << i << endl;
wcount++;
}
}
}
if (!wcount)
cout << "Didnt found!";
getchar();
return 0;
}
Немного порылся в интернете по пайтону:
text = input('введите текст ')
print(list(filter(lambda x: x.startswith("а"), text.split())))
print(list(filter(lambda x: x.endswith("а"), text.split())))
Но может кто то помочь именно по коду?
Python (3.8)
Здравствуйте. Мне нужно было сделать программу(на С++), когда вводишь слова, выводит слова, которые начинаются и заканчиваются на одну и ту же букву. А теперь нужно перевести ее на питон, кто то может помочь?
Код на С++
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
string s;
cout << "Input words:" << endl;
getline(cin, s);
stringstream strm(s);
cout << "Your words:" << endl;
int wcount{ 0 };
for (string i; strm >> i
int lenght = i.length() - 1;
if (i[0] == i[lenght]) {
cout << i << endl;
wcount++;
}
else if ((i[lenght] == '!') || (i[lenght] == '?') || (i[lenght] == '.'))
{
i.erase(lenght--);
if (i[0] == i[lenght]) {
cout << i << endl;
wcount++;
}
}
}
if (!wcount)
cout << "Didnt found!";
getchar();
return 0;
}
Немного порылся в интернете по пайтону:
text = input('введите текст ')
print(list(filter(lambda x: x.startswith("а"), text.split())))
print(list(filter(lambda x: x.endswith("а"), text.split())))
Но может кто то помочь именно по коду?