[Solved] What is the function for each Python data structures? [closed]


the only needed is list

I assume you talk about collections, because lists without atomic values to put into lists are worthless. Still, there are lots of things lists don’t work well for. Of course, if you never (or so rarely elegance and performance doesn’t matter) need to [better choices in brackets]…

  • Get a value by a key [dicts]
  • Check for membership in a set [sets]
  • Prevent duplicates [sets]
  • Perform set operations (union, difference, etc.) [sets]
  • Treat strings as text, not as collections of characters (e.g. title-case words) [string]
  • Model trees [depends, but frequently hand-rolled]
  • Model graphs (you wouldn’t believe how incredibly general those are) [dicts or hand-rolled]
  • Ensure immutability [tuple, frozenset, string]
  • Remove and add items at the beginning [dequeue]
  • Ensure FIFO (first in, first out) semantics [queue]

then you may get along with lists alone. And that’s just the uses cases the standard library collection types cover that I know off the top of my head. There are many other data types, and many more ways to use each collection.

I don’t know about you, but I’d estimate I don’t even use lists for half of my collection needs. It depends on the project, of course, but few problems only require sequences.

solved What is the function for each Python data structures? [closed]