当前位置:网站首页>Kickback -- find the first palindrome character in a group of characters
Kickback -- find the first palindrome character in a group of characters
2022-07-01 07:34:00 【Beauty of algorithm and programming】
introduction
This question is the first question of this week's buckle competition , We are learning to find palindromes python when , Will experience . Compared with the palindrome number , It would be easier to find palindrome charactersproblem
Here's an array of strings words, Find and return the first palindrome string in the array . If there is no string that meets the requirements , Returns an empty string ""
List
Input words = ["abc","car","ada","racecar","cool"]
Output :"ada"Method
Build a function f(x), utilize for in Loop through character groups words Every character of , Then use the method of slicing to make the characters turn upside down , Reuse conditions if To determine whether the inverted character is equal to the original character , If you encounter the first equality , Then output the character and end the function , If there is no equal , Just go back to ””Experimental results and discussion
Through the experiment 、 Practice has proved that the proposed method is effective , Is able to solve the problem raised at the beginning .
Code listdef f(x):
for i in x:
d = i[::-1]:
if d == i:
return i
return “”
words = ["abc","car","ada","racecar","cool"]
print(f(words))Conclusion
Do this question , First of all, you need to know what palindrome characters are , And should have a certain understanding of slicing , In order to complete this problem faster . It should be noted that , Use for in loop , Have a certain understanding of the operation and stop of the cycle . Available functions for this problem , It's not necessary , But Li Kou has strict requirements for format , You must use functions to
边栏推荐
- LeetCode+ 71 - 75
- Atguigu---- scaffold --02- use scaffold (2)
- 【R语言】两个/N个数据合并merge函数
- 如何让两融交易更极速
- ctfshow-web351(SSRF)
- [image processing] image histogram equalization system with GUI interface
- Alibaba OSS postman invalid according to policy: policy condition failed: ["starts with", "key", "test/"]
- Mysql与Redis一致性解决方案
- 组件的自定义事件②
- Warm congratulations on the successful listing of five elements hehe liquor
猜你喜欢

Alibaba OSS postman invalid according to policy: policy condition failed: ["starts with", "key", "test/"]

关系数据库如何工作

运维管理有什么实用的技巧吗

【Flutter 问题系列第 72 篇】在 Flutter 中使用 Camera 插件拍的图片被拉伸问题的解决方案

I bet on performance and won the CTO of the company. I want to build Devops platform!

Understanding of Turing test and Chinese Room

運維管理系統,人性化操作體驗

Eigen矩阵运算库快速上手

【目标检测】目标检测界的扛把子YOLOv5(原理详解+修炼指南)

How to create an exclusive vs Code theme
随机推荐
[image processing] image histogram equalization system with GUI interface
奥迪AUDI EDI 项目中供应商需要了解哪些信息?
redisson使用全解——redisson官方文檔+注釋(上篇)
ctfshow-web355,356(SSRF)
下载Xshell和Xftp
2022 tea master (intermediate) recurrent training question bank and answers
JSP - paging
Apple账号密码自动填充
Is it safe to buy funds on the brokerage account
[programming training] delete public characters (hash mapping) + team competition (greedy)
软件测试方法和技术 - 基础知识概括
Todolist classic case ①
Do securities account opening affect the security of account opening
Unity2021-Scene视图中物体无法直接选中的解决办法
【mysql学习笔记26】视图
Those high-frequency written tests and interview questions in [Jianzhi offer & Niuke 101] - linked list
2022 electrician (intermediate) recurrent training question bank and answers
未来互联网人才还稀缺吗?哪些技术方向热门?
The database is locked. Is there a solution
2022 test question bank and simulation test of tea master (primary) operation certificate