Python - Set Methods (Reversed) Flashcards

1
Q

set.remove(element)

A

Return - none
Args - ( value to remove )
___________
searches for the given element in the set and removes it.

If the element(argument) passed to the remove() method doesn’t exist, keyError exception is thrown.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

set.add(element)

A

Return - none
Args - ( value to add )
___________
adds a given element to a set. If the element is already present, it doesn’t add any element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

set.copy()

A

Return - none
Args - none
___________
makes a shallow copy. It doesn’t return any value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

set.clear()

A

Return - none
Args - none
___________
removes all elements from the set.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A.difference(B)

A

Return - set
Args - ( the set you wanna subtract out )
___________
returns the set difference of two sets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

s.discard(x)

A

Return - none
Args - ( value to remove from set )
___________
removes a specified element from the set (if present).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

A.intersection(*other_sets)

A

Return - set intersection
Args - ( sets to intersect with )
___________
returns the intersection of set A with all the sets (passed as argument).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

set_a.isdisjoint(set_b)

A

Return - bool
Args - ( second set or any iterable )
___________
returns True if two sets are disjoint sets. If not, it returns False.

You can also pass an iterable (list, tuple, dictionary and string) to disjoint(). The isdisjoint() method will automatically convert iterables to set and checks whether the sets are disjoint or not.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

A.issubset(B)

A

Return - bool
Args - ( superset you are taking subset from )
___________
returns True if all elements of a set are present in another set (passed as an argument). If not, it returns False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

A.issuperset(B)

A

Return - bool
Args - ( subset )
___________
returns True if a set has every elements of another set (passed as an argument). If not, it returns False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

set.pop()

A

Return - random value that is popped
Args - none
___________
removes an random/arbitrary element from the set and returns the element removed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

A.symmetric_difference(B)

A

Return - new set
Args - ( second set )
___________
returns a new set which is the symmetric difference of two sets.

The symmetric difference of two sets A and B is the set of elements which are in either of the sets A or B but not in both.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A.union(*other_sets)

A

Return - new set that is union of all sets
Args - ( other sets )
___________
returns a new set with distinct elements from all the sets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

A.update(B)

A

Return - none
Args - ( value to add to set, can be an iterable )
___________
adds elements from a set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

any(iterable)

A

Return - bool
Args - ( iterable )
___________
returns True if any element of an iterable is True. If not, any() returns False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

all(iterable)

A

Return - bool
Args - ( iterable )
___________
returns True if all elements of an iterable is True. If not, any() returns False.

17
Q

enumerate(iterable, start=0)

A

Return - enumerate object
Args - ( iterable )
___________
adds counter to an iterable and returns it (the enumerate object).

18
Q

set( iterable )

A

Return - set
Args - ( iterable )
___________
constructs a Python set from the given iterable and returns it.

19
Q

sorted( iterable, optional key, optional reverse)

A

Return - sorted list
Args - ( iterable, optional key, optional reverse )
___________
returns a sorted list from the given iterable.