10 Python One-Liners for Lists
Lists are one of the four built-in data structures (lists, tuples, sets and dictionaries) for holding a collection of objects in Python. Since we use lists so frequently, knowing a few one-liner code to work with lists can be greatly helpful. Here are ten of them which you may find yourself frequently using.
In all these examples, we will use the list cost=[23,24,26,29,41,29,35]
Note for adding or removing elements in a list, the one-liners that use the list methods and statements such as del
directly changes the original list whereas external…