Count number of gemstones in a set of minerals
Clash Royale CLAN TAG#URR8PPP
up vote
7
down vote
favorite
This is the "Gemstones" problem on Hackerrank.
John has collected various rocks. Each rock has various minerals embeded in it. Each type of mineral is designated by a lowercase letter in the range
a-z
. There may be multiple occurrences of a mineral in a rock. A mineral is called a gemstone if it occurs at least once in each of the rocks in John's collection.
Given a list of minerals embedded in each of John's rocks, display the number of types of gemstones he has in his collection.
For example, the array of mineral composition strings[abc, abc, bc]
The minerals b and c appear in each composite, so there are 2 gemstones.
This is my Python code:
def gemstones(arr):
for i in range(len(arr)):
arr[i] = "".join(set(arr[i]))
long = max(arr, key=len)
arrlen = len(arr)
flag,count = 0,0
for i in long:
for j in range(arrlen):
if i not in arr[j]: flag = 1
if flag is 0: count += 1
flag = 0
return count
Are there ways to improve this code? I feel I'm not using the full functionality of Python.
A test case:
>>> arr = ['abcdde', 'baccd', 'eeabg']
>>> print(gemstones(arr))
2
python strings programming-challenge
add a comment |Â
up vote
7
down vote
favorite
This is the "Gemstones" problem on Hackerrank.
John has collected various rocks. Each rock has various minerals embeded in it. Each type of mineral is designated by a lowercase letter in the range
a-z
. There may be multiple occurrences of a mineral in a rock. A mineral is called a gemstone if it occurs at least once in each of the rocks in John's collection.
Given a list of minerals embedded in each of John's rocks, display the number of types of gemstones he has in his collection.
For example, the array of mineral composition strings[abc, abc, bc]
The minerals b and c appear in each composite, so there are 2 gemstones.
This is my Python code:
def gemstones(arr):
for i in range(len(arr)):
arr[i] = "".join(set(arr[i]))
long = max(arr, key=len)
arrlen = len(arr)
flag,count = 0,0
for i in long:
for j in range(arrlen):
if i not in arr[j]: flag = 1
if flag is 0: count += 1
flag = 0
return count
Are there ways to improve this code? I feel I'm not using the full functionality of Python.
A test case:
>>> arr = ['abcdde', 'baccd', 'eeabg']
>>> print(gemstones(arr))
2
python strings programming-challenge
add a comment |Â
up vote
7
down vote
favorite
up vote
7
down vote
favorite
This is the "Gemstones" problem on Hackerrank.
John has collected various rocks. Each rock has various minerals embeded in it. Each type of mineral is designated by a lowercase letter in the range
a-z
. There may be multiple occurrences of a mineral in a rock. A mineral is called a gemstone if it occurs at least once in each of the rocks in John's collection.
Given a list of minerals embedded in each of John's rocks, display the number of types of gemstones he has in his collection.
For example, the array of mineral composition strings[abc, abc, bc]
The minerals b and c appear in each composite, so there are 2 gemstones.
This is my Python code:
def gemstones(arr):
for i in range(len(arr)):
arr[i] = "".join(set(arr[i]))
long = max(arr, key=len)
arrlen = len(arr)
flag,count = 0,0
for i in long:
for j in range(arrlen):
if i not in arr[j]: flag = 1
if flag is 0: count += 1
flag = 0
return count
Are there ways to improve this code? I feel I'm not using the full functionality of Python.
A test case:
>>> arr = ['abcdde', 'baccd', 'eeabg']
>>> print(gemstones(arr))
2
python strings programming-challenge
This is the "Gemstones" problem on Hackerrank.
John has collected various rocks. Each rock has various minerals embeded in it. Each type of mineral is designated by a lowercase letter in the range
a-z
. There may be multiple occurrences of a mineral in a rock. A mineral is called a gemstone if it occurs at least once in each of the rocks in John's collection.
Given a list of minerals embedded in each of John's rocks, display the number of types of gemstones he has in his collection.
For example, the array of mineral composition strings[abc, abc, bc]
The minerals b and c appear in each composite, so there are 2 gemstones.
This is my Python code:
def gemstones(arr):
for i in range(len(arr)):
arr[i] = "".join(set(arr[i]))
long = max(arr, key=len)
arrlen = len(arr)
flag,count = 0,0
for i in long:
for j in range(arrlen):
if i not in arr[j]: flag = 1
if flag is 0: count += 1
flag = 0
return count
Are there ways to improve this code? I feel I'm not using the full functionality of Python.
A test case:
>>> arr = ['abcdde', 'baccd', 'eeabg']
>>> print(gemstones(arr))
2
python strings programming-challenge
python strings programming-challenge
edited Oct 1 at 16:02
Mathias Ettinger
22.3k32976
22.3k32976
asked Oct 1 at 15:21
db18
13716
13716
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
9
down vote
You need to stop iterating over indexes and loop like a native. A first rewrite with that in mind would yield:
def gemstones(collection):
collection = [''.join(set(rock)) for rock in collection]
biggest_rock = max(collection, key=len)
count = 0
for mineral in biggest_rock:
for rock in collection:
if mineral not in rock:
break
else:
count += 1
return count
This version make use for the for...else
construct. But the all()
builtin would be more expressive:
def gemstones(collection):
collection = [''.join(set(rock)) for rock in collection]
biggest_rock = max(collection, key=len)
count = 0
for mineral in biggest_rock:
if all(mineral in rock for rock in collection):
count += 1
return count
And counting a condition in a for-loop can be more efficient using sum()
:
def gemstones(collection):
collection = [''.join(set(rock)) for rock in collection]
biggest_rock = max(collection, key=len)
return sum(
all(mineral in rock for rock in collection)
for mineral in biggest_rock
)
Other than that, you won't have more gemstones than the amount of minerals in the smallest rock, so why doing extra work by using the biggest one to start with?
But you are going back and forth between strings and sets when the problem clearly calls for set intersection repeated on several elements of an array. Luckily, the set.intersection
method accept a variable number of arguments. Just make sure to catch any error thrown in case the original collection is empty:
def gemstone(collection):
rocks = map(set, collection)
try:
minerals = next(rocks)
except StopIteration:
return 0 # If the collection is empty, there is no gemstones
return len(minerals.intersection(*rocks))
# If the collection is empty, there are no gemstones
Python... always the naive implementation that gets ripped to shreds by native implementation... I'm not sure there anything that you can do in python that can't be turned into a list of native operations... Oh wait. Same goes for every language... Maybe python just has more than js.
â FreezePhoenix
Oct 1 at 17:00
@FreezePhoenix I don't get what you're trying to convey. I could have usednext(rocks, set())
to avoid the wholetry
and achieve the same result, is it somewhat related?
â Mathias Ettinger
Oct 1 at 17:07
What I meant was that JS doesn't have as much built in as Python does.
â FreezePhoenix
Oct 1 at 17:25
Why not just refactorexcept StopIteration: return 0
tominerals = next(rocks, 0)
?next
has its second argument the default value for a good reason.
â Voile
Oct 2 at 4:17
1
@Voile For starter it should benext(rocks, set())
instead, and its perfectly valid, yes, see my previous comment. But then, it's more of a personal taste in this particular case, building an empty set each time and not using it most of the time feels odd to me, IâÂÂd rather spend a tiny extra time in exception handling the rare timescollection
is empty⦠Or even don't care at all, since OP code doesn't (max
willTypeError
ifarr
is empty).
â Mathias Ettinger
Oct 2 at 8:08
 |Â
show 1 more comment
up vote
2
down vote
You could do this in one line:
rocks = ['abcdde', 'baccd', 'eeabg']
len(set.intersection(*[set(r) for r in rocks]))
To get the actual set, leave off the len(...)
bit, of course, or replace it with list(...)
if you prefer the result as a list instead of a set.
add a comment |Â
up vote
1
down vote
An alternative way to solve this is to just write down the problem description in Python:
rocks = ['abcdde', 'baccd', 'eeabg']
def is_gemstone(mineral):
return all(mineral in rock for rock in rocks)
minerals = mineral for rock in rocks for mineral in rock
gemstones = mineral for mineral in minerals if is_gemstone(mineral)
print(len(gemstones))
New contributor
3
Welcome to Code Review. On this site we like answers that explain the process of improving the code more than the actual result. Currently you have an improved version of the code here but not so much explanation to it.
â Simon Forsbergâ¦
Oct 1 at 21:06
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
9
down vote
You need to stop iterating over indexes and loop like a native. A first rewrite with that in mind would yield:
def gemstones(collection):
collection = [''.join(set(rock)) for rock in collection]
biggest_rock = max(collection, key=len)
count = 0
for mineral in biggest_rock:
for rock in collection:
if mineral not in rock:
break
else:
count += 1
return count
This version make use for the for...else
construct. But the all()
builtin would be more expressive:
def gemstones(collection):
collection = [''.join(set(rock)) for rock in collection]
biggest_rock = max(collection, key=len)
count = 0
for mineral in biggest_rock:
if all(mineral in rock for rock in collection):
count += 1
return count
And counting a condition in a for-loop can be more efficient using sum()
:
def gemstones(collection):
collection = [''.join(set(rock)) for rock in collection]
biggest_rock = max(collection, key=len)
return sum(
all(mineral in rock for rock in collection)
for mineral in biggest_rock
)
Other than that, you won't have more gemstones than the amount of minerals in the smallest rock, so why doing extra work by using the biggest one to start with?
But you are going back and forth between strings and sets when the problem clearly calls for set intersection repeated on several elements of an array. Luckily, the set.intersection
method accept a variable number of arguments. Just make sure to catch any error thrown in case the original collection is empty:
def gemstone(collection):
rocks = map(set, collection)
try:
minerals = next(rocks)
except StopIteration:
return 0 # If the collection is empty, there is no gemstones
return len(minerals.intersection(*rocks))
# If the collection is empty, there are no gemstones
Python... always the naive implementation that gets ripped to shreds by native implementation... I'm not sure there anything that you can do in python that can't be turned into a list of native operations... Oh wait. Same goes for every language... Maybe python just has more than js.
â FreezePhoenix
Oct 1 at 17:00
@FreezePhoenix I don't get what you're trying to convey. I could have usednext(rocks, set())
to avoid the wholetry
and achieve the same result, is it somewhat related?
â Mathias Ettinger
Oct 1 at 17:07
What I meant was that JS doesn't have as much built in as Python does.
â FreezePhoenix
Oct 1 at 17:25
Why not just refactorexcept StopIteration: return 0
tominerals = next(rocks, 0)
?next
has its second argument the default value for a good reason.
â Voile
Oct 2 at 4:17
1
@Voile For starter it should benext(rocks, set())
instead, and its perfectly valid, yes, see my previous comment. But then, it's more of a personal taste in this particular case, building an empty set each time and not using it most of the time feels odd to me, IâÂÂd rather spend a tiny extra time in exception handling the rare timescollection
is empty⦠Or even don't care at all, since OP code doesn't (max
willTypeError
ifarr
is empty).
â Mathias Ettinger
Oct 2 at 8:08
 |Â
show 1 more comment
up vote
9
down vote
You need to stop iterating over indexes and loop like a native. A first rewrite with that in mind would yield:
def gemstones(collection):
collection = [''.join(set(rock)) for rock in collection]
biggest_rock = max(collection, key=len)
count = 0
for mineral in biggest_rock:
for rock in collection:
if mineral not in rock:
break
else:
count += 1
return count
This version make use for the for...else
construct. But the all()
builtin would be more expressive:
def gemstones(collection):
collection = [''.join(set(rock)) for rock in collection]
biggest_rock = max(collection, key=len)
count = 0
for mineral in biggest_rock:
if all(mineral in rock for rock in collection):
count += 1
return count
And counting a condition in a for-loop can be more efficient using sum()
:
def gemstones(collection):
collection = [''.join(set(rock)) for rock in collection]
biggest_rock = max(collection, key=len)
return sum(
all(mineral in rock for rock in collection)
for mineral in biggest_rock
)
Other than that, you won't have more gemstones than the amount of minerals in the smallest rock, so why doing extra work by using the biggest one to start with?
But you are going back and forth between strings and sets when the problem clearly calls for set intersection repeated on several elements of an array. Luckily, the set.intersection
method accept a variable number of arguments. Just make sure to catch any error thrown in case the original collection is empty:
def gemstone(collection):
rocks = map(set, collection)
try:
minerals = next(rocks)
except StopIteration:
return 0 # If the collection is empty, there is no gemstones
return len(minerals.intersection(*rocks))
# If the collection is empty, there are no gemstones
Python... always the naive implementation that gets ripped to shreds by native implementation... I'm not sure there anything that you can do in python that can't be turned into a list of native operations... Oh wait. Same goes for every language... Maybe python just has more than js.
â FreezePhoenix
Oct 1 at 17:00
@FreezePhoenix I don't get what you're trying to convey. I could have usednext(rocks, set())
to avoid the wholetry
and achieve the same result, is it somewhat related?
â Mathias Ettinger
Oct 1 at 17:07
What I meant was that JS doesn't have as much built in as Python does.
â FreezePhoenix
Oct 1 at 17:25
Why not just refactorexcept StopIteration: return 0
tominerals = next(rocks, 0)
?next
has its second argument the default value for a good reason.
â Voile
Oct 2 at 4:17
1
@Voile For starter it should benext(rocks, set())
instead, and its perfectly valid, yes, see my previous comment. But then, it's more of a personal taste in this particular case, building an empty set each time and not using it most of the time feels odd to me, IâÂÂd rather spend a tiny extra time in exception handling the rare timescollection
is empty⦠Or even don't care at all, since OP code doesn't (max
willTypeError
ifarr
is empty).
â Mathias Ettinger
Oct 2 at 8:08
 |Â
show 1 more comment
up vote
9
down vote
up vote
9
down vote
You need to stop iterating over indexes and loop like a native. A first rewrite with that in mind would yield:
def gemstones(collection):
collection = [''.join(set(rock)) for rock in collection]
biggest_rock = max(collection, key=len)
count = 0
for mineral in biggest_rock:
for rock in collection:
if mineral not in rock:
break
else:
count += 1
return count
This version make use for the for...else
construct. But the all()
builtin would be more expressive:
def gemstones(collection):
collection = [''.join(set(rock)) for rock in collection]
biggest_rock = max(collection, key=len)
count = 0
for mineral in biggest_rock:
if all(mineral in rock for rock in collection):
count += 1
return count
And counting a condition in a for-loop can be more efficient using sum()
:
def gemstones(collection):
collection = [''.join(set(rock)) for rock in collection]
biggest_rock = max(collection, key=len)
return sum(
all(mineral in rock for rock in collection)
for mineral in biggest_rock
)
Other than that, you won't have more gemstones than the amount of minerals in the smallest rock, so why doing extra work by using the biggest one to start with?
But you are going back and forth between strings and sets when the problem clearly calls for set intersection repeated on several elements of an array. Luckily, the set.intersection
method accept a variable number of arguments. Just make sure to catch any error thrown in case the original collection is empty:
def gemstone(collection):
rocks = map(set, collection)
try:
minerals = next(rocks)
except StopIteration:
return 0 # If the collection is empty, there is no gemstones
return len(minerals.intersection(*rocks))
You need to stop iterating over indexes and loop like a native. A first rewrite with that in mind would yield:
def gemstones(collection):
collection = [''.join(set(rock)) for rock in collection]
biggest_rock = max(collection, key=len)
count = 0
for mineral in biggest_rock:
for rock in collection:
if mineral not in rock:
break
else:
count += 1
return count
This version make use for the for...else
construct. But the all()
builtin would be more expressive:
def gemstones(collection):
collection = [''.join(set(rock)) for rock in collection]
biggest_rock = max(collection, key=len)
count = 0
for mineral in biggest_rock:
if all(mineral in rock for rock in collection):
count += 1
return count
And counting a condition in a for-loop can be more efficient using sum()
:
def gemstones(collection):
collection = [''.join(set(rock)) for rock in collection]
biggest_rock = max(collection, key=len)
return sum(
all(mineral in rock for rock in collection)
for mineral in biggest_rock
)
Other than that, you won't have more gemstones than the amount of minerals in the smallest rock, so why doing extra work by using the biggest one to start with?
But you are going back and forth between strings and sets when the problem clearly calls for set intersection repeated on several elements of an array. Luckily, the set.intersection
method accept a variable number of arguments. Just make sure to catch any error thrown in case the original collection is empty:
def gemstone(collection):
rocks = map(set, collection)
try:
minerals = next(rocks)
except StopIteration:
return 0 # If the collection is empty, there is no gemstones
return len(minerals.intersection(*rocks))
edited Oct 1 at 16:36
answered Oct 1 at 15:53
Mathias Ettinger
22.3k32976
22.3k32976
# If the collection is empty, there are no gemstones
Python... always the naive implementation that gets ripped to shreds by native implementation... I'm not sure there anything that you can do in python that can't be turned into a list of native operations... Oh wait. Same goes for every language... Maybe python just has more than js.
â FreezePhoenix
Oct 1 at 17:00
@FreezePhoenix I don't get what you're trying to convey. I could have usednext(rocks, set())
to avoid the wholetry
and achieve the same result, is it somewhat related?
â Mathias Ettinger
Oct 1 at 17:07
What I meant was that JS doesn't have as much built in as Python does.
â FreezePhoenix
Oct 1 at 17:25
Why not just refactorexcept StopIteration: return 0
tominerals = next(rocks, 0)
?next
has its second argument the default value for a good reason.
â Voile
Oct 2 at 4:17
1
@Voile For starter it should benext(rocks, set())
instead, and its perfectly valid, yes, see my previous comment. But then, it's more of a personal taste in this particular case, building an empty set each time and not using it most of the time feels odd to me, IâÂÂd rather spend a tiny extra time in exception handling the rare timescollection
is empty⦠Or even don't care at all, since OP code doesn't (max
willTypeError
ifarr
is empty).
â Mathias Ettinger
Oct 2 at 8:08
 |Â
show 1 more comment
# If the collection is empty, there are no gemstones
Python... always the naive implementation that gets ripped to shreds by native implementation... I'm not sure there anything that you can do in python that can't be turned into a list of native operations... Oh wait. Same goes for every language... Maybe python just has more than js.
â FreezePhoenix
Oct 1 at 17:00
@FreezePhoenix I don't get what you're trying to convey. I could have usednext(rocks, set())
to avoid the wholetry
and achieve the same result, is it somewhat related?
â Mathias Ettinger
Oct 1 at 17:07
What I meant was that JS doesn't have as much built in as Python does.
â FreezePhoenix
Oct 1 at 17:25
Why not just refactorexcept StopIteration: return 0
tominerals = next(rocks, 0)
?next
has its second argument the default value for a good reason.
â Voile
Oct 2 at 4:17
1
@Voile For starter it should benext(rocks, set())
instead, and its perfectly valid, yes, see my previous comment. But then, it's more of a personal taste in this particular case, building an empty set each time and not using it most of the time feels odd to me, IâÂÂd rather spend a tiny extra time in exception handling the rare timescollection
is empty⦠Or even don't care at all, since OP code doesn't (max
willTypeError
ifarr
is empty).
â Mathias Ettinger
Oct 2 at 8:08
# If the collection is empty, there are no gemstones
Python... always the naive implementation that gets ripped to shreds by native implementation... I'm not sure there anything that you can do in python that can't be turned into a list of native operations... Oh wait. Same goes for every language... Maybe python just has more than js.â FreezePhoenix
Oct 1 at 17:00
# If the collection is empty, there are no gemstones
Python... always the naive implementation that gets ripped to shreds by native implementation... I'm not sure there anything that you can do in python that can't be turned into a list of native operations... Oh wait. Same goes for every language... Maybe python just has more than js.â FreezePhoenix
Oct 1 at 17:00
@FreezePhoenix I don't get what you're trying to convey. I could have used
next(rocks, set())
to avoid the whole try
and achieve the same result, is it somewhat related?â Mathias Ettinger
Oct 1 at 17:07
@FreezePhoenix I don't get what you're trying to convey. I could have used
next(rocks, set())
to avoid the whole try
and achieve the same result, is it somewhat related?â Mathias Ettinger
Oct 1 at 17:07
What I meant was that JS doesn't have as much built in as Python does.
â FreezePhoenix
Oct 1 at 17:25
What I meant was that JS doesn't have as much built in as Python does.
â FreezePhoenix
Oct 1 at 17:25
Why not just refactor
except StopIteration: return 0
to minerals = next(rocks, 0)
? next
has its second argument the default value for a good reason.â Voile
Oct 2 at 4:17
Why not just refactor
except StopIteration: return 0
to minerals = next(rocks, 0)
? next
has its second argument the default value for a good reason.â Voile
Oct 2 at 4:17
1
1
@Voile For starter it should be
next(rocks, set())
instead, and its perfectly valid, yes, see my previous comment. But then, it's more of a personal taste in this particular case, building an empty set each time and not using it most of the time feels odd to me, IâÂÂd rather spend a tiny extra time in exception handling the rare times collection
is empty⦠Or even don't care at all, since OP code doesn't (max
will TypeError
if arr
is empty).â Mathias Ettinger
Oct 2 at 8:08
@Voile For starter it should be
next(rocks, set())
instead, and its perfectly valid, yes, see my previous comment. But then, it's more of a personal taste in this particular case, building an empty set each time and not using it most of the time feels odd to me, IâÂÂd rather spend a tiny extra time in exception handling the rare times collection
is empty⦠Or even don't care at all, since OP code doesn't (max
will TypeError
if arr
is empty).â Mathias Ettinger
Oct 2 at 8:08
 |Â
show 1 more comment
up vote
2
down vote
You could do this in one line:
rocks = ['abcdde', 'baccd', 'eeabg']
len(set.intersection(*[set(r) for r in rocks]))
To get the actual set, leave off the len(...)
bit, of course, or replace it with list(...)
if you prefer the result as a list instead of a set.
add a comment |Â
up vote
2
down vote
You could do this in one line:
rocks = ['abcdde', 'baccd', 'eeabg']
len(set.intersection(*[set(r) for r in rocks]))
To get the actual set, leave off the len(...)
bit, of course, or replace it with list(...)
if you prefer the result as a list instead of a set.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
You could do this in one line:
rocks = ['abcdde', 'baccd', 'eeabg']
len(set.intersection(*[set(r) for r in rocks]))
To get the actual set, leave off the len(...)
bit, of course, or replace it with list(...)
if you prefer the result as a list instead of a set.
You could do this in one line:
rocks = ['abcdde', 'baccd', 'eeabg']
len(set.intersection(*[set(r) for r in rocks]))
To get the actual set, leave off the len(...)
bit, of course, or replace it with list(...)
if you prefer the result as a list instead of a set.
answered Oct 1 at 18:17
twalberg
1412
1412
add a comment |Â
add a comment |Â
up vote
1
down vote
An alternative way to solve this is to just write down the problem description in Python:
rocks = ['abcdde', 'baccd', 'eeabg']
def is_gemstone(mineral):
return all(mineral in rock for rock in rocks)
minerals = mineral for rock in rocks for mineral in rock
gemstones = mineral for mineral in minerals if is_gemstone(mineral)
print(len(gemstones))
New contributor
3
Welcome to Code Review. On this site we like answers that explain the process of improving the code more than the actual result. Currently you have an improved version of the code here but not so much explanation to it.
â Simon Forsbergâ¦
Oct 1 at 21:06
add a comment |Â
up vote
1
down vote
An alternative way to solve this is to just write down the problem description in Python:
rocks = ['abcdde', 'baccd', 'eeabg']
def is_gemstone(mineral):
return all(mineral in rock for rock in rocks)
minerals = mineral for rock in rocks for mineral in rock
gemstones = mineral for mineral in minerals if is_gemstone(mineral)
print(len(gemstones))
New contributor
3
Welcome to Code Review. On this site we like answers that explain the process of improving the code more than the actual result. Currently you have an improved version of the code here but not so much explanation to it.
â Simon Forsbergâ¦
Oct 1 at 21:06
add a comment |Â
up vote
1
down vote
up vote
1
down vote
An alternative way to solve this is to just write down the problem description in Python:
rocks = ['abcdde', 'baccd', 'eeabg']
def is_gemstone(mineral):
return all(mineral in rock for rock in rocks)
minerals = mineral for rock in rocks for mineral in rock
gemstones = mineral for mineral in minerals if is_gemstone(mineral)
print(len(gemstones))
New contributor
An alternative way to solve this is to just write down the problem description in Python:
rocks = ['abcdde', 'baccd', 'eeabg']
def is_gemstone(mineral):
return all(mineral in rock for rock in rocks)
minerals = mineral for rock in rocks for mineral in rock
gemstones = mineral for mineral in minerals if is_gemstone(mineral)
print(len(gemstones))
New contributor
New contributor
answered Oct 1 at 16:56
folkol
1193
1193
New contributor
New contributor
3
Welcome to Code Review. On this site we like answers that explain the process of improving the code more than the actual result. Currently you have an improved version of the code here but not so much explanation to it.
â Simon Forsbergâ¦
Oct 1 at 21:06
add a comment |Â
3
Welcome to Code Review. On this site we like answers that explain the process of improving the code more than the actual result. Currently you have an improved version of the code here but not so much explanation to it.
â Simon Forsbergâ¦
Oct 1 at 21:06
3
3
Welcome to Code Review. On this site we like answers that explain the process of improving the code more than the actual result. Currently you have an improved version of the code here but not so much explanation to it.
â Simon Forsbergâ¦
Oct 1 at 21:06
Welcome to Code Review. On this site we like answers that explain the process of improving the code more than the actual result. Currently you have an improved version of the code here but not so much explanation to it.
â Simon Forsbergâ¦
Oct 1 at 21:06
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f204712%2fcount-number-of-gemstones-in-a-set-of-minerals%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password