{"id":111178,"date":"2020-04-06T14:53:12","date_gmt":"2020-04-06T14:53:12","guid":{"rendered":"https:\/\/blog.finxter.com\/?p=7348"},"modified":"2020-04-06T14:53:12","modified_gmt":"2020-04-06T14:53:12","slug":"how-to-create-your-own-search-engine-in-a-single-line-of-python","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2020\/04\/06\/how-to-create-your-own-search-engine-in-a-single-line-of-python\/","title":{"rendered":"How to Create Your Own Search Engine in a Single Line of Python?"},"content":{"rendered":"<p>This Python One-Liner is part of my<a href=\"https:\/\/www.amazon.com\/gp\/product\/B07ZY7XMX8\" target=\"_blank\" rel=\"noreferrer noopener\"> Python One-Liners book <\/a>with NoStarch Press.<\/p>\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\">\n<div class=\"wp-block-embed__wrapper\">\n<div class=\"ast-oembed-container\"><iframe loading=\"lazy\" title=\"Python One-Liners - Trick 4 - How to Create Your Own Little Search Engine in One Line?\" width=\"1400\" height=\"788\" src=\"https:\/\/www.youtube.com\/embed\/5egoqwCACkY?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/div>\n<\/div>\n<\/figure>\n<p>Here&#8217;s the code from the video:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">letters_amazon = '''\nWe spent several years building our own database engine,\nAmazon Aurora, a fully-managed MySQL and PostgreSQL-compatible\nservice with the same or better durability and availability as\nthe commercial engines, but at one-tenth of the cost. We were\nnot surprised when this worked. ''' find = lambda x, q: x[x.find(q)-18:x.find(q)+18] if q in x else -1 print(find(letters_amazon, 'SQL'))\n<\/pre>\n<p>Try It Yourself:<\/p>\n<p> <iframe loading=\"lazy\" height=\"600px\" width=\"100%\" src=\"https:\/\/repl.it\/@finxter\/PythonOneLinerSearchEngine?lite=true\" scrolling=\"no\" frameborder=\"no\" allowtransparency=\"true\" allowfullscreen=\"true\" sandbox=\"allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-modals\"><\/iframe> <\/p>\n<p>Related Articles:<\/p>\n<ul>\n<li><a href=\"https:\/\/blog.finxter.com\/introduction-to-slicing-in-python\/\" target=\"_blank\" rel=\"noreferrer noopener\">Python Slicing<\/a><\/li>\n<li><a href=\"https:\/\/blog.finxter.com\/if-then-else-in-one-line-python\/\" target=\"_blank\" rel=\"noreferrer noopener\">Ternary Operator in Python<\/a><\/li>\n<li><a href=\"https:\/\/blog.finxter.com\/a-simple-introduction-of-the-lambda-function-in-python\/\">Lambda Function<\/a><\/li>\n<li><a href=\"https:\/\/blog.finxter.com\/python-re-findall\/\" target=\"_blank\" rel=\"noreferrer noopener\">Find Function<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This Python One-Liner is part of my Python One-Liners book with NoStarch Press. Here&#8217;s the code from the video: letters_amazon = &#8221;&#8217; We spent several years building our own database engine, Amazon Aurora, a fully-managed MySQL and PostgreSQL-compatible service with the same or better durability and availability as the commercial engines, but at one-tenth of [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[857],"tags":[73,468,528],"class_list":["post-111178","post","type-post","status-publish","format-standard","hentry","category-python-tut","tag-programming","tag-python","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/111178","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=111178"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/111178\/revisions"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=111178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=111178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=111178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}