Python Language Set: Difference between revisions
Jump to navigation
Jump to search
Line 37: | Line 37: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Does not return anything. | Does not return anything. | ||
=Convert to List= | |||
<syntaxhighlight lang='py'> | |||
s=set() | |||
l=list(s) | |||
</syntaxhighlight> |
Revision as of 22:25, 9 September 2022
Internal
TODO
- TO PROCESS PyOOP "Sets"
Overview
Initialization
Literal initialization:
s = {1, 2, 3}
Set from a tuple:
s = set((1, 2, 3))
Set from a list:
s = set([1, 2, 3])
Set from a string:
s = set('ABC')
print(s) # {'C', 'B', 'A'}
Shallow Copy
s = set()
s.add('a')
s2 = s.copy()
Remove an Element from a Set
s.remove('a')
Does not return anything.
Convert to List
s=set()
l=list(s)