#๐ Python complexity
12 messages ยท Page 1 of 1 (latest)
@tiny sapphire
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
list lookup is O(n), set lookup is O(1)
@tiny sapphire Karma gave you the correct answer. Did you have any other questions?
Thank you!
I'm good
testing for membership in a set is O(1)
!d set - everything is hashed (under the hood); technically its like comparing with a hashmap.
class set([iterable])``````py
class frozenset([iterable])```
Return a new set or frozenset object whose elements are taken from *iterable*. The elements of a set must be [hashable](https://docs.python.org/3/glossary.html#term-hashable). To represent sets of sets, the inner sets must be [`frozenset`](https://docs.python.org/3/library/stdtypes.html#frozenset) objects. If *iterable* is not specified, a new empty set is returned.
Sets can be created by several means:
โข Use a comma\-separated list of elements within braces: `{'jack', 'sjoerd'}`
โข Use a set comprehension: `{c for c in 'abracadabra' if c not in 'abc'}`
โข Use the type constructor: `set()`, `set('foobar')`, `set(['a', 'b', 'foo'])`...
Similar names: label.set
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.