Data and AI Centralโ€™s Post

View organization page for Data and AI Central, graphic

32,311 followers

๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐—Ÿ๐—ถ๐˜€๐˜ ๐— ๐—ฒ๐˜๐—ต๐—ผ๐—ฑ๐˜€ ๐—™๐—ฟ๐—ผ๐—บ ๐—ฎ ๐——๐—ถ๐—ณ๐—ณ๐—ฒ๐—ฟ๐—ฒ๐—ป๐˜ ๐—”๐—ป๐—ด๐—น๐—ฒ Let's dive in with some real-world analogies and examples! ๐Ÿ”น ๐—ฎ๐—ฝ๐—ฝ๐—ฒ๐—ป๐—ฑ() - ๐—ง๐—ต๐—ฒ ๐—ฃ๐—ฎ๐—ฟ๐˜๐˜† ๐—ฃ๐—น๐—ฎ๐—ป๐—ป๐—ฒ๐—ฟ Imagine you're organizing a party. As you think of more friends to invite, you keep adding them to your guest list. In Python, this is just like using ๐šŠ๐š™๐š™๐šŽ๐š—๐š(). It adds an element to the end of the list. guest_list = ['Alice', 'Bob'] guest_list.append('Charlie') print(guest_list)ย # Output: ['Alice', 'Bob', 'Charlie'] ๐Ÿ”น ๐—ฒ๐˜…๐˜๐—ฒ๐—ป๐—ฑ() - ๐—ง๐—ต๐—ฒ ๐— ๐—ฒ๐—ฟ๐—ด๐—ถ๐—ป๐—ด ๐—ผ๐—ณ ๐—ง๐—ฟ๐—ถ๐—ฏ๐—ฒ๐˜€ Think of two music bands deciding to perform together. They merge their members into one big band. Similarly, ๐šŽ๐šก๐š๐šŽ๐š—๐š() merges one list into another. band_one = ['Drummer', 'Guitarist'] band_two = ['Singer', 'Bassist'] band_one.extend(band_two) print(band_one)ย # Output: ['Drummer', 'Guitarist', 'Singer', 'Bassist'] ๐Ÿ”น ๐—ฟ๐—ฒ๐—บ๐—ผ๐˜ƒ๐—ฒ() - ๐—ฆ๐—ฝ๐—ฟ๐—ถ๐—ป๐—ด ๐—–๐—น๐—ฒ๐—ฎ๐—ป๐—ถ๐—ป๐—ด Ever cleaned your room and removed items you no longer need? ๐š›๐šŽ๐š–๐š˜๐šŸ๐šŽ() does this for lists, eliminating the first occurrence of a specified element. items = ['books', 'pen', 'notebook', 'pen'] items.remove('pen') print(items)ย # Output: ['books', 'notebook', 'pen'] ๐Ÿ”น ๐—ฝ๐—ผ๐—ฝ() - ๐—ง๐—ต๐—ฒ ๐—ฆ๐˜‚๐—ฟ๐—ฝ๐—ฟ๐—ถ๐˜€๐—ฒ ๐—•๐—ผ๐˜… Imagine a box where you take out the topmost item without knowing what it is. ๐š™๐š˜๐š™() removes and returns the last element of the list (or a specified index). colors = ['red', 'green', 'blue'] print(colors.pop())ย # Output: 'blue' print(colors)ย # Output: ['red', 'green'] ๐Ÿ”น ๐˜€๐—ผ๐—ฟ๐˜() - ๐—ง๐—ต๐—ฒ ๐—Ÿ๐—ถ๐—ฏ๐—ฟ๐—ฎ๐—ฟ๐—ถ๐—ฎ๐—ปโ€™๐˜€ ๐— ๐—ฒ๐˜๐—ต๐—ผ๐—ฑ Think of a librarian arranging books in alphabetical order. ๐šœ๐š˜๐š›๐š() arranges elements of the list in a specific order (default is ascending). numbers = [3, 1, 4, 1, 5, 9] numbers.sort() print(numbers)ย # Output: [1, 1, 3, 4, 5, 9] ๐Ÿ”น ๐—ฟ๐—ฒ๐˜ƒ๐—ฒ๐—ฟ๐˜€๐—ฒ() - ๐—ง๐—ถ๐—บ๐—ฒ ๐—ง๐—ฟ๐—ฎ๐˜ƒ๐—ฒ๐—น๐—ฒ๐—ฟโ€™๐˜€ ๐—š๐—น๐—ถ๐—บ๐—ฝ๐˜€๐—ฒ Ever wished to rewind your day and revisit events in reverse? That's what ๐š›๐šŽ๐šŸ๐šŽ๐š›๐šœ๐šŽ() does to a list. timeline = ['morning', 'afternoon', 'evening'] timeline.reverse() print(timeline)ย # Output: ['evening', 'afternoon', 'morning'] ๐Ÿ”น ๐—ถ๐—ป๐—ฑ๐—ฒ๐˜…() - ๐—ง๐—ต๐—ฒ ๐—ง๐—ฟ๐—ฒ๐—ฎ๐˜€๐˜‚๐—ฟ๐—ฒ ๐—›๐˜‚๐—ป๐˜ Finding a specific item in a cluttered room can be a challenge. Similarly, ๐š’๐š—๐š๐šŽ๐šก() helps find the position of an element in the list. fruits = ['apple', 'banana', 'cherry'] print(fruits.index('banana'))ย # Output: 1 ๐Ÿ”น ๐—ฐ๐—ผ๐˜‚๐—ป๐˜() - ๐—ง๐—ต๐—ฒ ๐—ฃ๐—ผ๐—น๐—น ๐—ง๐—ฎ๐—ธ๐—ฒ๐—ฟ Ever conducted a poll and counted votes for each option? ๐šŒ๐š˜๐šž๐š—๐š() does this for occurrences of an element in a list. votes = ['yes', 'no', 'yes', 'yes', 'no'] print(votes.count('yes'))ย # Output: 3 โžก Stay tuned and make sure to follow us at Data and AI Central ๐Ÿš€ for more FREE resources! #python #data #machinelearning #ai #artificialintelligence #datascience #analytics #software #webdevelopment #developer #automation #technology #programming #coding #tech #learning

  • No alternative text description for this image

Pop will not return the remaining list, itโ€™ll return the popped element.

Omri Gindi

Software Engineer - Meta Tel Aviv

1mo

Does this format really help anyone???

Maicon Stihler

Full time Professor at CEFET-MG

1mo

Maybe it would be better to change "output" to "side effect", because some of these methods do not return/output anything (e.g., append) while others do (e.g., pop).

Iโ€™m tired of developers spamming this format. Iโ€™ve seen two dozens of them now in my feed.

Tobi Bello

Quapost | PostStudent

1mo

Donโ€™t forget this knowledge is useful in python but other languages is where you learn that appending a variable that shares its address with another could cause unintended effects most of these donโ€™t work if you want to write safe cide . Rust user and c programmer speaking ๐Ÿ˜‚

Like
Reply

A helpful simple visual representation that is remarkably easy to recall Salutations!

Like
Reply

Love the analogies! Makes Python lists super relatable. Do these methods come in handy for AI projects at Data and AI Central? Alex Belov

Like
Reply
Harshitha Harsh

โœจI help Businesses Upskill their Employees in DevOps | DevOps Mentor & Process Architect

1mo

Learning Python list manipulations is like having a magic wand to organize things easily! If you could use one Python list manipulation function in your daily life, which one would it be and why?

Like
Reply
Gina Acosta Gutiรฉrrez

Data Analyst | Data Engineer | AI | GenAI | Mentor | Content Creator ๐Ÿ‘ฉ๐Ÿป๐Ÿ’ป | Google WTM Ambassador | Python | Tableau | Snowflake | Power BI | Business Intelligence

1mo

Helpful guide! Simplified explanations enhance comprehension of Python list manipulation.

Like
Reply
Semeh Ben Salem, PhD

โž• 15K๐Ÿš€ | TECH LEAD DATA @Econocom | MCT Regional Lead | 3xMCT | PL100 | PL300 | PL900 | DP100 | DP203 | DP300 | DP500 | DP900 | AI102 | AI900 | AZ900 | SC900 | Databricks Apache Spark Certified | PCEP | PSM | PSPO

1mo

Thanks for sharing ๐Ÿ’ช๐Ÿ’ช

Like
Reply
See more comments

To view or add a comment, sign in

Explore topics