Automatically translated.View original post

🐍 Daily Python Problem: Find a Simple Repeat 💖

Today we meet the Daily Python Problem: find a duplicate! ✨

The problem is to write the find _ common _ elements function (list1, list2) that will be returned as a new list that only appears on both lists.

There are three ways to write the code:

1. Basic (Loop): This method is easy and straightforward for beginners.

2.Pythonic (Use List Comprehension): Short, concise, popular for Python writers!

3. Pro (Use Set): This method is the fastest (especially with big lists) because it uses the Set feature to find the Intersection (duplicate part) with a sign & then convert it back to list!

Let's take a few examples:

• Input: find _ common _ elements ([1, 2, 3, 4], [3, 4, 5, 6])

• Output: [3, 4]

Try to practice writing together. Finding the duplicate part is used very often! 👩‍💻

Keep going. 🥰

# python # programmer # data aanalyst # ai # learnonlemon8

2025/11/9 Edited to

... Read moreถ้าใครกำลังหา “ตัวอย่าง Python” หรือ “python ตัวอย่าง” แบบเอาไปใช้ได้จริง โจทย์หาตัวซ้ำระหว่าง 2 list คือหนึ่งในแพตเทิร์นที่เจอบ่อยมาก ทั้งงาน data, งานเขียนสคริปต์, หรือทำแบบฝึกหัดสัมภาษณ์ค่ะ ต่อไปนี้เป็นตัวอย่างเพิ่มเติมที่ช่วยให้ใช้งานได้ครอบคลุมขึ้น (จากที่เรามี Loop / List Comprehension / Set แล้ว) 1) เคสที่มี “ตัวซ้ำซ้อน” ภายใน list เดียวกัน บางที list1 อาจมีเลข 3 ซ้ำหลายครั้ง แต่เราอยากได้ผลลัพธ์แบบไม่ซ้ำ (unique) หรืออยากคงจำนวนซ้ำไว้ก็ได้ - แบบเอา unique (เหมาะกับใช้ set): ผลลัพธ์จะเป็นสมาชิกที่ซ้ำกันแบบไม่ซ้ำซ้อน เช่น [3, 4] - แบบคงลำดับและคงจำนวนที่ซ้ำ (เหมาะกับ loop): ถ้า list1 = [1,3,3,4] และ list2 = [3,4] ผลลัพธ์อาจได้ [3,3,4] (ขึ้นกับกติกาที่เราต้องการ) ทริคคือ “กำหนด requirement ก่อน” ว่าต้องการ unique หรือ preserve duplicates 2) เคสที่ต้อง “รักษาลำดับเดิม” ของ list1 Set จะเร็วมาก แต่ไม่รับประกันลำดับ (แม้เวอร์ชันใหม่ๆ จะดูเหมือนเรียงได้บ้างในบางกรณี แต่ไม่ควรพึ่งพา) ถ้าอยากได้ลำดับตาม list1 แนะนำแนวนี้: - สร้าง set ของ list2 ไว้เช็คเร็วๆ - วน list1 แล้วเช็คว่า item อยู่ใน set2 ไหม แนวนี้ได้ทั้งความเร็วและรักษาลำดับ 3) เคส list เป็น “ข้อความ” หรือ “คำ” จาก OCR ก็มีตัวอย่างว่าหาได้ทั้งตัวเลขและข้อความ เช่น list1 = ["apple", "banana", "kiwi"] list2 = ["kiwi", "orange", "banana"] ผลลัพธ์ควรได้ ["banana", "kiwi"] (ถ้ารักษาลำดับ list1) 4) โบนัส: “สระทั้งหมด” ในภาษาไทย (เชื่อมกับคีย์เวิร์ดที่คนค้นหา) ถ้าโจทย์ของคุณเกี่ยวกับการหาสระในข้อความ สามารถใช้แนวคิดเดียวกันได้เลย เช่นเตรียมลิสต์/เซ็ตของสระ แล้วเช็คว่าตัวอักษรไหนอยู่ในกลุ่มสระ ตัวอย่างชุดสระที่คนมักใช้ (ปรับเพิ่มได้ตามงาน): สระ = "ะาิีึืุูเแโใไๅำ" แล้ววนอ่านทีละตัวอักษรในข้อความ เพื่อดึงเฉพาะตัวที่อยู่ในสระ (เหมือนการหา common elements ระหว่าง “ตัวอักษรในข้อความ” กับ “ชุดสระ”) 5) เลือกวิธีไหนดี? - ข้อมูลน้อย/อยากอ่านง่าย: Loop หรือ List Comprehension - ข้อมูลเยอะ/เน้นเร็ว: Set intersection (&) หรือใช้ set ช่วยเช็คสมาชิก - ต้องรักษาลำดับ: Loop + set ของอีกฝั่ง ลองปรับโจทย์ find_common_elements ให้รองรับเคสพวกนี้ จะได้เป็น “ตัวอย่าง python” ที่ใช้งานจริงมากขึ้น และเอาไปต่อยอดกับโจทย์แนวข้อความ/สระทั้งหมดได้ด้วยค่ะ

Related posts

A woman in a bikini stands on a sandy path leading to a beach with the ocean and a sailboat in the background, under the title 'Part I - Health Hyperfeminine Glow Up Guide DAILY ROUTINE'.
Text on a white background introduces Phase 1 of the Hyperfeminine Glow Up Level Up Series: Health, emphasizing its importance and focusing on nutrition, exercise, sleep, and oral health.
Text on a white background details nutrition tips for fueling the body, including whole foods, essential nutrients like vitamins A, B, C, D, Omega-3s, and hydration, with a peach slice graphic.
Glow up in all areas of life to be more feminine✨🌸
Welcome to Phase 1 of my Hyperfeminine Glow Up Level Up Series: Health! This phase is all about laying the groundwork to become the best version of yourself. Every aspect of beauty—from your hair to your smile—begins with your health. Think of it as investing in your ultimate glow up, starting
Chalie_Baker

Chalie_Baker

2202 likes

A study desk with an iPad, highlighter, textbook, and notes, featuring the title "How to get a 4.00 GPA Based on your Major" and "All majors included!".
Strategies for Business & Management Majors (Business Management, Accounting, Finance, Economics), including Active Participation, Case Study Analysis, Practice Financial Modeling, and Utilize Study Groups, with mentions of MarketingSherpa and GroupMe.
Strategies for Communications & Education Majors (Communications, Education), including Create Multimedia Presentations, Peer Teaching, Reflective Journaling, and Attend Workshops, with mentions of Canva and Notion.
Major-Specific Strategies to Achieve a ✨4.0 GPA✨🎓🧠
🎓1. Business & Management Majors (Business Management, Accounting, Finance, Economics) ✅Active Participation: Example: In a Marketing class, when discussing a case study like Coca-Cola’s rebranding, share your analysis of the marketing mix (4Ps). This not only engages you in the materi
Chalie_Baker

Chalie_Baker

7061 likes

how I got started learning Python 🐍💻👾
I’ve been learning Python this summer to prepare for my research lab and courses in the fall. Programming isn’t required for my major, so I’m taking the time to learn it alone. The biggest tip I can give is specific goals from the beginning! Speaking from experience, this will save a lot of time an
reagan

reagan

46 likes

🔥 Assign Multiple Values in Python (Easy!)
🔥 Assign Multiple Values in Python (Easy!) Assigning multiple values in Python makes your code shorter, cleaner, and more readable 💻 Perfect trick for beginners and interview prep 🚀 Save this post and follow for daily Python tips 🐍 #Python #LearnPython #PythonBasics #PythonTips
TechKeysX

TechKeysX

0 likes

You Don’t Have A Manifestation Problem. You Not Taking Action.
You don’t have a manifestation problem or motivation problem you just not taking actions. You’re not stuck… you’re just not taking action. Every day your mind gives you ideas that could change your life—but fear, overthinking, and perfectionism keep you from moving. This week, be intentional. On
Carline Menard

Carline Menard

18 likes

Useful Python libraries for Data Analysts
Hello everyone! I wanted to highlight key Python libraries for data analysts that I find very useful! To start with, Pandas library excels in data manipulation with DataFrames and Series. NumPy supports efficient handling of large arrays and mathematical operations. Matplotlib offers versatile plot
Yun Jung

Yun Jung

63 likes

A computer screen displays a game interface with Python-like code on the right and a farming simulation on the left, illustrating how the game teaches coding. The text overlay asks, "this game teaches you how to code!?"
A computer screen shows a game with multiple code windows and a farming simulation. An overlay explains the game's language is similar to Python, suitable for beginners and experienced coders with complex challenges.
A computer screen displays a game's text editor and entity list, including "can_harvest" and "range." Overlays state "the farmer was replaced" and explain the game teaches coding basics to build a foundation for further self-study.
this cute app can teach you how to code python
ive always wanted to learn how to code more than html and css, something on the complex side. it always has seemed intimidating until i stumbled upon this game/app where the task are gamified, so its seems more fun to explore rather than formal courses. are you willing to give it a shot? #l
yuuki

yuuki

372 likes

Bible Study Feels Confusing? Heres The Fix
S.O.A.P Bible Study Template [LINK IN BIO] Bible study feels confusing? This fixes it. A simple S.O.A.P. page that tells you exactly what to write next. No overwhelm. Just one free template to keep your study time with God consistent. #biblehack #biblestudy #biblejournaling #God
DailyBreadDesigns

DailyBreadDesigns

15 likes

A vibrant image featuring a waterfall and lush greenery, with large pink text overlaying it that reads "YOU NEED TO HEAR THIS.. AFFIRMATIONS." The Lemon8 logo and username are visible in the bottom left.
A close-up of a person's eye and eyebrow, overlaid with two black boxes containing daily affirmations numbered 1 through 10, such as "I am worthy of love" and "I am grateful for the blessings."
A beach scene with the ocean and sand, featuring two black boxes displaying daily affirmations numbered 11 through 20, including "I am in charge of my thoughts" and "I am healthy, strong, and full of energy."
30 Daily Affirmations You Need To Hear …
These daily affirmations will inspire positivity, confidence & growth. 💘 save this for your daily read🫶🏽 Repeat these affirmations daily to create a positive mindset & empower yourself! ⬇️👇🏽⬇️👇🏽⬇️👇🏽⬇️👇🏽⬇️👇🏽⬇️👇🏽⬇️👇🏽⬇️👇🏽⬇️ Here’s 10 more to make it 30 🗓️ 21. I am confident in my
KAREN💄POSTS BEAUTY

KAREN💄POSTS BEAUTY

149 likes

A person's legs, clad in brown cowboy boots, are casually propped out of a car window at night. The image is overlaid with the text "COUNTRY MUSIC I KEEP ON REPEAT" and musical notes, suggesting a love for country music.
A Spotify screen displays Zach Top's song "Use Me" from the album "Cold Beer & Country Music." The album cover features Zach Top, a man with a mustache and cowboy hat, wearing a striped western shirt.
A Spotify screen shows Hudson Westbrook's song "Take Your Time." The album art depicts a man with blonde hair and a baseball cap sitting in the bed of an old red pickup truck, playing an acoustic guitar.
country music I keep on repeat
some of my fav songs at the moment.. drop some recommendations for meee!!! #country #music #countrymusic #boots #western
ciara 🌻

ciara 🌻

20 likes

Move. Laugh. REPEAT!
Let’s get real for a sec—working out isn’t about looking perfect, having the cutest matching set, or hitting the fanciest gym. It’s about MOVING your body, feeling strong, and having FUN while doing it! Maybe you feel silly doing your dance cardio in the living room or trying new moves that loo
gymkat

gymkat

10 likes

A scenic sunset over a rural landscape with trees and an ATV in the foreground. Overlay text reads "COUNTRY SONGS I HAVE ON REPEAT."
A Spotify album cover for "I'm A Little Crazy" by Morgan Wallen, featuring a painted portrait of the artist looking to the left.
A Spotify album cover for "Gucci Mane" by Jessie Murph, depicting a person in high heels and a white outfit reclining by a mirror.
Country songs I have on repeat 🌾🤠
The best of the best ✨ drop any song recommendations you may have below ⬇️🫶🏼
Trin

Trin

411 likes

Python Variable Names Explained (Avoid These Mista
Confused by Python code? 😵‍💫 The problem might be bad variable names. In this post, you’ll learn: ✔ What variable names are ✔ Rules you must follow ✔ Good vs bad examples ✔ Pro tips to write clean Python code Save this post 📌 and follow for more Python basics made easy 🐍✨ #Python #LearnPy
TechKeysX

TechKeysX

0 likes

Useful third-party Python libraries
A key advantage of Python is its rich ecosystem of libraries. Beyond the powerful standard library, Python boasts a vast collection of third-party packages and frameworks that significantly boost productivity and simplify development across countless domains Here are useful and popular third-par
Learn Tech with Dan

Learn Tech with Dan

114 likes

A woman with curly hair holds a microphone, presenting a title card that reads 'Data Analysis with Python For Beginners'.
A woman with curly hair holds a microphone, presenting an introductory text about simple steps for learning Python for Data Analysis.
A woman with curly hair holds a microphone, presenting a list of four steps for beginners to learn Python for Data Analysis.
Beginner Friendly Tips For Learning Python for Dat
If I was to learn Python for Data Analysis as a beginner, I would start with the basics, I would learn: Variables Data Types Loops and Functions. There's no Python without libraries and these are the most used for Data Analysis: 👉 Pandas - Data Manipulation 👉 Numpy - Numerical Comput
NeLo

NeLo

77 likes

Tips for having a happy ball python
#lemon8diarychallenge I love my reptiles🥰 #petsnake #ballpython #reptilekeeper #reptile
jordynemilee

jordynemilee

49 likes

A collage showing items for pet odor control: baking soda, enzyme cleaner, dog collars, a black light, a rubber broom on a rug, and a clean home interior.
A bottle of enzyme cleaner spray, used for breaking down pet odors rather than just covering them, sits on a countertop.
A hand holds a black light flashlight, a tool used to quickly spot hidden pet messes and odors on surfaces.
How I Keep my Home Pet-Odor Free (w/ two dogs)
I love having dogs, but keeping the house smelling fresh does take some effort. Over time, I’ve picked up a few simple tricks that really help. So much so that when friends come over, they’re usually surprised to find out I have dogs - because the house just doesn’t smell like it. It’s not about sc
Anna Brynn

Anna Brynn

219 likes

Repeat!
Fav country songs!
Izzy falcone

Izzy falcone

269 likes

New Morphe “Python Code” Palette 🐍
#morphe #morphe eyeshadow palette #makeup #newmakeup #trend United States
Veronica Priscila Arnold🥀🦂

Veronica Priscila Arnold🥀🦂

462 likes

Global Variables in Python 🌍
Global variables allow data to be shared across your program, but misuse can lead to bugs. Learn when and how to use them correctly in Python 🐍 #Python #PythonBasics #LearnPython #Coding #Programming
TechKeysX

TechKeysX

0 likes

5 Best YouTube Channels for Python & Data Science
#pythonforbeginners #datasciencetips #learntocode #youtubelearning #techcareers
Aysha

Aysha

111 likes

My ball python gets a new home!
I can’t wait to get him all set up, he’s gonna love it and I’m just excited to see him explore his new home😍🥰 #ballpython #ballpythons #snake #reptile #reptilesoflemon8
Magan Celine

Magan Celine

2 likes

A view from an airplane window showing the wing, blue sky, and land below, with text overlayed: 'Best programming language for BEGINNERS (3 reasons why) SWIPE' and 'TECH CAREER TIPS'.
A dirt road in a hilly, arid landscape with distant buildings and the sea, featuring text: '1. Beginner-Friendly and Easy to Learn' explaining Python's simple syntax and extensive support.
A dirt road in a hilly, arid landscape with distant buildings and the sea, featuring text: '2. Versatility Across Fields' detailing Python's use in web development, data science, AI, and various industries.
Why Python is the best programming language 👩‍💻
1. Beginner-Friendly and Easy to Learn - Python's syntax is simple and intuitive, resembling everyday language, making it accessible for people with no programming background. - It has an extensive library of tutorials, documentation, and community support, making it an ideal first lang
vedha | career tips (tech) 👩‍

vedha | career tips (tech) 👩‍

8 likes

DAILY AT HOME FULL BODY WORKOUT 💪🏾🔥
This JazzTooFit Daily Workout Routine is built to tone your glutes, legs, arms, and core with just a set of dumbbells. Short on time? No problem. Let’s get to work. Daily Workout Routine: 10 Sumo Squats 10 DB Swings 10 Step Hammer Press 10 Bicep Curls 10 Deadlifts 💪🏽 Repeat 2–3 rounds 🎯
JazzTooFit

JazzTooFit

0 likes

See more