inputs
stringlengths 50
14k
| targets
stringlengths 4
655k
|
---|---|
## **Instructions**
The goal of this kata is two-fold:
1.) You must produce a fibonacci sequence in the form of an array, containing a number of items equal to the input provided.
2.) You must replace all numbers in the sequence `divisible by 3` with `Fizz`, those `divisible by 5` with `Buzz`, and those `divisible by both 3 and 5` with `FizzBuzz`.
For the sake of this kata, you can assume all input will be a positive integer.
## **Use Cases**
Return output must be in the form of an array, with the numbers as integers and the replaced numbers (fizzbuzz) as strings.
## **Examples**
Input:
```python
fibs_fizz_buzz(5)
```
Output:
~~~~
[ 1, 1, 2, 'Fizz', 'Buzz' ]
~~~~
Input:
```python
fibs_fizz_buzz(1)
```
Output:
~~~~
[1]
~~~~
Input:
```python
fibs_fizz_buzz(20)
```
Output:
~~~~
[1,1,2,"Fizz","Buzz",8,13,"Fizz",34,"Buzz",89,"Fizz",233,377,"Buzz","Fizz",1597,2584,4181,"FizzBuzz"]
~~~~
##Good Luck!##
|
def fib(n):
f = [1,1]
while len(f) < n:
f.append(f[-2]+f[-1])
return f[:n]
def fizz_buzzify(l):
return ["Fizz"*(n%3==0)+"Buzz"*(n%5==0) or n for n in l]
def fibs_fizz_buzz(n):
return fizz_buzzify(fib(n))
|
The function sigma 1, σ1 in mathematics, is known as the one that gives the sum of the divisors of an integer number.
For example for the number 10,
```python
σ1(10) = 18 # because the divisors of 10 are: 1, 2, 5, 10
σ1(10) = 1 + 2 + 5 + 10 = 18
```
You can see the graph of this important function up to 250:
The number 528 and its reversed, 825 have equal value for the function σ1.
```python
σ1(528) = σ1(825)
divisors of 528 are: 1, 2, 3, 4, 6, 8, 11, 12, 16, 22, 24, 33, 44, 48, 66, 88, 132, 176, 264 and 528
the sum of the divisors of 528 is 1488
divisors of 825 are: 1, 3, 5, 11, 15, 25, 33, 55, 75, 165, 275 and 825
the sum of the divisors of 825 is 1488
```
In fact 528 is the smallest non palindromic integer that has this property.
We need a function, ```equal_sigma1()```, that may collect all the positive integers that fulfill the property described above.
The function receives an upper limit, ```nMax```, will output the total sum of these numbers and its reversed while are less or equal nMax.
Let's see some cases:
```python
equal_sigma1(100) = 0 # There are no numbers.
equal_sigma1(1000) = 1353 # 528 and its revesed 825 were found, 528 + 825 = 1353
equal_sigma1(2000) = 4565 # There are four numbers_: 528 + 825 + 1561 + 1651 = 4565
equal_sigma1(1600) = 2914 # Now we have three numbers: 528 + 825 + 1561 = 2914
equal_sigma1(1561) = 2914
```
The palindromic numbers (like 88, 808, 929), numbers that are equal to its reversed should be discarded.
Happy coding!!
(For more information about the general sigma function see at: https://en.wikipedia.org/wiki/Divisor_function)
|
cache = {}
def sum_div(x):
if x not in cache:
cache[x] = sum(i for i in range(1, x+1) if x % i == 0)
return cache[x]
def is_required(x):
reversed = int(str(x)[::-1])
return x != reversed and sum_div(x) == sum_div(reversed)
required = [x for x in range(528, 10**4) if is_required(x)]
def equal_sigma1(nMax):
return sum(x for x in required if x <= nMax)
|
The function sigma 1, σ1 in mathematics, is known as the one that gives the sum of the divisors of an integer number.
For example for the number 10,
```python
σ1(10) = 18 # because the divisors of 10 are: 1, 2, 5, 10
σ1(10) = 1 + 2 + 5 + 10 = 18
```
You can see the graph of this important function up to 250:
The number 528 and its reversed, 825 have equal value for the function σ1.
```python
σ1(528) = σ1(825)
divisors of 528 are: 1, 2, 3, 4, 6, 8, 11, 12, 16, 22, 24, 33, 44, 48, 66, 88, 132, 176, 264 and 528
the sum of the divisors of 528 is 1488
divisors of 825 are: 1, 3, 5, 11, 15, 25, 33, 55, 75, 165, 275 and 825
the sum of the divisors of 825 is 1488
```
In fact 528 is the smallest non palindromic integer that has this property.
We need a function, ```equal_sigma1()```, that may collect all the positive integers that fulfill the property described above.
The function receives an upper limit, ```nMax```, will output the total sum of these numbers and its reversed while are less or equal nMax.
Let's see some cases:
```python
equal_sigma1(100) = 0 # There are no numbers.
equal_sigma1(1000) = 1353 # 528 and its revesed 825 were found, 528 + 825 = 1353
equal_sigma1(2000) = 4565 # There are four numbers_: 528 + 825 + 1561 + 1651 = 4565
equal_sigma1(1600) = 2914 # Now we have three numbers: 528 + 825 + 1561 = 2914
equal_sigma1(1561) = 2914
```
The palindromic numbers (like 88, 808, 929), numbers that are equal to its reversed should be discarded.
Happy coding!!
(For more information about the general sigma function see at: https://en.wikipedia.org/wiki/Divisor_function)
|
def sigma1(n):
ans = 0
for i in xrange(1,int(n**0.5) + 1):
if n % i == 0:
ans += i + n / i
return ans if n ** 0.5 % 1 != 0 else ans - int(n ** 0.5)
def equal_sigma1(n_max):
ans = 0
for i in xrange(528,n_max+1):
j = int(str(i)[::-1])
if i != j and sigma1(i) == sigma1(j):ans += i
return ans
|
The function sigma 1, σ1 in mathematics, is known as the one that gives the sum of the divisors of an integer number.
For example for the number 10,
```python
σ1(10) = 18 # because the divisors of 10 are: 1, 2, 5, 10
σ1(10) = 1 + 2 + 5 + 10 = 18
```
You can see the graph of this important function up to 250:
The number 528 and its reversed, 825 have equal value for the function σ1.
```python
σ1(528) = σ1(825)
divisors of 528 are: 1, 2, 3, 4, 6, 8, 11, 12, 16, 22, 24, 33, 44, 48, 66, 88, 132, 176, 264 and 528
the sum of the divisors of 528 is 1488
divisors of 825 are: 1, 3, 5, 11, 15, 25, 33, 55, 75, 165, 275 and 825
the sum of the divisors of 825 is 1488
```
In fact 528 is the smallest non palindromic integer that has this property.
We need a function, ```equal_sigma1()```, that may collect all the positive integers that fulfill the property described above.
The function receives an upper limit, ```nMax```, will output the total sum of these numbers and its reversed while are less or equal nMax.
Let's see some cases:
```python
equal_sigma1(100) = 0 # There are no numbers.
equal_sigma1(1000) = 1353 # 528 and its revesed 825 were found, 528 + 825 = 1353
equal_sigma1(2000) = 4565 # There are four numbers_: 528 + 825 + 1561 + 1651 = 4565
equal_sigma1(1600) = 2914 # Now we have three numbers: 528 + 825 + 1561 = 2914
equal_sigma1(1561) = 2914
```
The palindromic numbers (like 88, 808, 929), numbers that are equal to its reversed should be discarded.
Happy coding!!
(For more information about the general sigma function see at: https://en.wikipedia.org/wiki/Divisor_function)
|
import bisect
def s1(n):
result = 0
for i in range(1, int(n ** 0.5)+1):
q, r = divmod(n, i)
if r == 0:
result += i
if q != i:
result += q
return result
dup = set()
for i in range(10001):
ss = str(i)
rr = ss[::-1]
if ss >= rr:
continue
if s1(i) == s1(int(rr)):
dup.add(i)
dup.add(int(rr))
dup = sorted(dup)
def equal_sigma1(nMax):
return sum(dup[:bisect.bisect(dup, nMax)])
|
The function sigma 1, σ1 in mathematics, is known as the one that gives the sum of the divisors of an integer number.
For example for the number 10,
```python
σ1(10) = 18 # because the divisors of 10 are: 1, 2, 5, 10
σ1(10) = 1 + 2 + 5 + 10 = 18
```
You can see the graph of this important function up to 250:
The number 528 and its reversed, 825 have equal value for the function σ1.
```python
σ1(528) = σ1(825)
divisors of 528 are: 1, 2, 3, 4, 6, 8, 11, 12, 16, 22, 24, 33, 44, 48, 66, 88, 132, 176, 264 and 528
the sum of the divisors of 528 is 1488
divisors of 825 are: 1, 3, 5, 11, 15, 25, 33, 55, 75, 165, 275 and 825
the sum of the divisors of 825 is 1488
```
In fact 528 is the smallest non palindromic integer that has this property.
We need a function, ```equal_sigma1()```, that may collect all the positive integers that fulfill the property described above.
The function receives an upper limit, ```nMax```, will output the total sum of these numbers and its reversed while are less or equal nMax.
Let's see some cases:
```python
equal_sigma1(100) = 0 # There are no numbers.
equal_sigma1(1000) = 1353 # 528 and its revesed 825 were found, 528 + 825 = 1353
equal_sigma1(2000) = 4565 # There are four numbers_: 528 + 825 + 1561 + 1651 = 4565
equal_sigma1(1600) = 2914 # Now we have three numbers: 528 + 825 + 1561 = 2914
equal_sigma1(1561) = 2914
```
The palindromic numbers (like 88, 808, 929), numbers that are equal to its reversed should be discarded.
Happy coding!!
(For more information about the general sigma function see at: https://en.wikipedia.org/wiki/Divisor_function)
|
def sigma1(n):
return sum(set(sum(([k, n//k] for k in range(2, int(n**0.5) + 1) if not n % k), [1, n])))
def equal_sigma1(limit):
return sum(n for n in range(limit + 1) if n != int(str(n)[::-1]) and sigma1(n) == sigma1(int(str(n)[::-1])))
|
The function sigma 1, σ1 in mathematics, is known as the one that gives the sum of the divisors of an integer number.
For example for the number 10,
```python
σ1(10) = 18 # because the divisors of 10 are: 1, 2, 5, 10
σ1(10) = 1 + 2 + 5 + 10 = 18
```
You can see the graph of this important function up to 250:
The number 528 and its reversed, 825 have equal value for the function σ1.
```python
σ1(528) = σ1(825)
divisors of 528 are: 1, 2, 3, 4, 6, 8, 11, 12, 16, 22, 24, 33, 44, 48, 66, 88, 132, 176, 264 and 528
the sum of the divisors of 528 is 1488
divisors of 825 are: 1, 3, 5, 11, 15, 25, 33, 55, 75, 165, 275 and 825
the sum of the divisors of 825 is 1488
```
In fact 528 is the smallest non palindromic integer that has this property.
We need a function, ```equal_sigma1()```, that may collect all the positive integers that fulfill the property described above.
The function receives an upper limit, ```nMax```, will output the total sum of these numbers and its reversed while are less or equal nMax.
Let's see some cases:
```python
equal_sigma1(100) = 0 # There are no numbers.
equal_sigma1(1000) = 1353 # 528 and its revesed 825 were found, 528 + 825 = 1353
equal_sigma1(2000) = 4565 # There are four numbers_: 528 + 825 + 1561 + 1651 = 4565
equal_sigma1(1600) = 2914 # Now we have three numbers: 528 + 825 + 1561 = 2914
equal_sigma1(1561) = 2914
```
The palindromic numbers (like 88, 808, 929), numbers that are equal to its reversed should be discarded.
Happy coding!!
(For more information about the general sigma function see at: https://en.wikipedia.org/wiki/Divisor_function)
|
n = 100000
s = list(range(1, n+2))
for d in range(2, int(n**.5) + 1):
for i in range(d*d, n+1, d):
s[i] += d
s[i] += i//d
s[d*d] -= d
def equal_sigma1(n):
return sum(x for x in range(n+1)
if str(x) != str(x)[::-1] and s[x] == s[int(str(x)[::-1])])
|
The function sigma 1, σ1 in mathematics, is known as the one that gives the sum of the divisors of an integer number.
For example for the number 10,
```python
σ1(10) = 18 # because the divisors of 10 are: 1, 2, 5, 10
σ1(10) = 1 + 2 + 5 + 10 = 18
```
You can see the graph of this important function up to 250:
The number 528 and its reversed, 825 have equal value for the function σ1.
```python
σ1(528) = σ1(825)
divisors of 528 are: 1, 2, 3, 4, 6, 8, 11, 12, 16, 22, 24, 33, 44, 48, 66, 88, 132, 176, 264 and 528
the sum of the divisors of 528 is 1488
divisors of 825 are: 1, 3, 5, 11, 15, 25, 33, 55, 75, 165, 275 and 825
the sum of the divisors of 825 is 1488
```
In fact 528 is the smallest non palindromic integer that has this property.
We need a function, ```equal_sigma1()```, that may collect all the positive integers that fulfill the property described above.
The function receives an upper limit, ```nMax```, will output the total sum of these numbers and its reversed while are less or equal nMax.
Let's see some cases:
```python
equal_sigma1(100) = 0 # There are no numbers.
equal_sigma1(1000) = 1353 # 528 and its revesed 825 were found, 528 + 825 = 1353
equal_sigma1(2000) = 4565 # There are four numbers_: 528 + 825 + 1561 + 1651 = 4565
equal_sigma1(1600) = 2914 # Now we have three numbers: 528 + 825 + 1561 = 2914
equal_sigma1(1561) = 2914
```
The palindromic numbers (like 88, 808, 929), numbers that are equal to its reversed should be discarded.
Happy coding!!
(For more information about the general sigma function see at: https://en.wikipedia.org/wiki/Divisor_function)
|
import math
def find_sum_of_divisors(number):
not_divisible = []
sum = 1 + number
for div in xrange(2, int(round(math.sqrt(number)+1))):
if number % div == 0:
sum += div + number/div
return sum
def equal_sigma1(nMax):
checked_numbers = set()
found_sum = 0
for num in xrange(528, nMax+1):
if num in checked_numbers:
continue
number = str(num)
rev_number = number[::-1]
rev_num = int(rev_number)
checked_numbers.add(num)
checked_numbers.add(rev_num)
if number == rev_number:
continue
if find_sum_of_divisors(num) == find_sum_of_divisors(rev_num):
found_sum += num + (rev_num if rev_num <= nMax else 0)
return found_sum #sum of found numbers
|
The function sigma 1, σ1 in mathematics, is known as the one that gives the sum of the divisors of an integer number.
For example for the number 10,
```python
σ1(10) = 18 # because the divisors of 10 are: 1, 2, 5, 10
σ1(10) = 1 + 2 + 5 + 10 = 18
```
You can see the graph of this important function up to 250:
The number 528 and its reversed, 825 have equal value for the function σ1.
```python
σ1(528) = σ1(825)
divisors of 528 are: 1, 2, 3, 4, 6, 8, 11, 12, 16, 22, 24, 33, 44, 48, 66, 88, 132, 176, 264 and 528
the sum of the divisors of 528 is 1488
divisors of 825 are: 1, 3, 5, 11, 15, 25, 33, 55, 75, 165, 275 and 825
the sum of the divisors of 825 is 1488
```
In fact 528 is the smallest non palindromic integer that has this property.
We need a function, ```equal_sigma1()```, that may collect all the positive integers that fulfill the property described above.
The function receives an upper limit, ```nMax```, will output the total sum of these numbers and its reversed while are less or equal nMax.
Let's see some cases:
```python
equal_sigma1(100) = 0 # There are no numbers.
equal_sigma1(1000) = 1353 # 528 and its revesed 825 were found, 528 + 825 = 1353
equal_sigma1(2000) = 4565 # There are four numbers_: 528 + 825 + 1561 + 1651 = 4565
equal_sigma1(1600) = 2914 # Now we have three numbers: 528 + 825 + 1561 = 2914
equal_sigma1(1561) = 2914
```
The palindromic numbers (like 88, 808, 929), numbers that are equal to its reversed should be discarded.
Happy coding!!
(For more information about the general sigma function see at: https://en.wikipedia.org/wiki/Divisor_function)
|
def sigma(n):
r = 0
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
r += i + n // i
if n ** 0.5 % 1 != 0: return r
else: return r - int(n ** 0.5)
def equal_sigma1(nmax):
i, s = 2, 0
while i <= nmax:
rev = int(str(i)[::-1])
if i != rev and sigma(i) == sigma(rev):
s += i
i += 1
return s
|
The function sigma 1, σ1 in mathematics, is known as the one that gives the sum of the divisors of an integer number.
For example for the number 10,
```python
σ1(10) = 18 # because the divisors of 10 are: 1, 2, 5, 10
σ1(10) = 1 + 2 + 5 + 10 = 18
```
You can see the graph of this important function up to 250:
The number 528 and its reversed, 825 have equal value for the function σ1.
```python
σ1(528) = σ1(825)
divisors of 528 are: 1, 2, 3, 4, 6, 8, 11, 12, 16, 22, 24, 33, 44, 48, 66, 88, 132, 176, 264 and 528
the sum of the divisors of 528 is 1488
divisors of 825 are: 1, 3, 5, 11, 15, 25, 33, 55, 75, 165, 275 and 825
the sum of the divisors of 825 is 1488
```
In fact 528 is the smallest non palindromic integer that has this property.
We need a function, ```equal_sigma1()```, that may collect all the positive integers that fulfill the property described above.
The function receives an upper limit, ```nMax```, will output the total sum of these numbers and its reversed while are less or equal nMax.
Let's see some cases:
```python
equal_sigma1(100) = 0 # There are no numbers.
equal_sigma1(1000) = 1353 # 528 and its revesed 825 were found, 528 + 825 = 1353
equal_sigma1(2000) = 4565 # There are four numbers_: 528 + 825 + 1561 + 1651 = 4565
equal_sigma1(1600) = 2914 # Now we have three numbers: 528 + 825 + 1561 = 2914
equal_sigma1(1561) = 2914
```
The palindromic numbers (like 88, 808, 929), numbers that are equal to its reversed should be discarded.
Happy coding!!
(For more information about the general sigma function see at: https://en.wikipedia.org/wiki/Divisor_function)
|
# If a sequence has very few elements, it is best to compute enough of it at first
# And then just iterate over it
res = [528, 825, 1561, 1651, 4064, 4604, 5346, 6435, 5795, 5975]
def equal_sigma1(nMax):
return sum(x for x in res if x <= nMax)
|
The function sigma 1, σ1 in mathematics, is known as the one that gives the sum of the divisors of an integer number.
For example for the number 10,
```python
σ1(10) = 18 # because the divisors of 10 are: 1, 2, 5, 10
σ1(10) = 1 + 2 + 5 + 10 = 18
```
You can see the graph of this important function up to 250:
The number 528 and its reversed, 825 have equal value for the function σ1.
```python
σ1(528) = σ1(825)
divisors of 528 are: 1, 2, 3, 4, 6, 8, 11, 12, 16, 22, 24, 33, 44, 48, 66, 88, 132, 176, 264 and 528
the sum of the divisors of 528 is 1488
divisors of 825 are: 1, 3, 5, 11, 15, 25, 33, 55, 75, 165, 275 and 825
the sum of the divisors of 825 is 1488
```
In fact 528 is the smallest non palindromic integer that has this property.
We need a function, ```equal_sigma1()```, that may collect all the positive integers that fulfill the property described above.
The function receives an upper limit, ```nMax```, will output the total sum of these numbers and its reversed while are less or equal nMax.
Let's see some cases:
```python
equal_sigma1(100) = 0 # There are no numbers.
equal_sigma1(1000) = 1353 # 528 and its revesed 825 were found, 528 + 825 = 1353
equal_sigma1(2000) = 4565 # There are four numbers_: 528 + 825 + 1561 + 1651 = 4565
equal_sigma1(1600) = 2914 # Now we have three numbers: 528 + 825 + 1561 = 2914
equal_sigma1(1561) = 2914
```
The palindromic numbers (like 88, 808, 929), numbers that are equal to its reversed should be discarded.
Happy coding!!
(For more information about the general sigma function see at: https://en.wikipedia.org/wiki/Divisor_function)
|
f_d=lambda m:sum(set(sum([[i,m//i]for i in range(1,int(m**.5)+1)if m%i==0],[])))
equal_sigma1=lambda n:sum(set(sum([[i,int(str(i)[::-1])if int(str(i)[::-1])<=n else 0]for i in range(2,n+1)if str(i)!=str(i)[::-1]and f_d(i)==f_d(int(str(i)[::-1]))>0],[])))
|
The function sigma 1, σ1 in mathematics, is known as the one that gives the sum of the divisors of an integer number.
For example for the number 10,
```python
σ1(10) = 18 # because the divisors of 10 are: 1, 2, 5, 10
σ1(10) = 1 + 2 + 5 + 10 = 18
```
You can see the graph of this important function up to 250:
The number 528 and its reversed, 825 have equal value for the function σ1.
```python
σ1(528) = σ1(825)
divisors of 528 are: 1, 2, 3, 4, 6, 8, 11, 12, 16, 22, 24, 33, 44, 48, 66, 88, 132, 176, 264 and 528
the sum of the divisors of 528 is 1488
divisors of 825 are: 1, 3, 5, 11, 15, 25, 33, 55, 75, 165, 275 and 825
the sum of the divisors of 825 is 1488
```
In fact 528 is the smallest non palindromic integer that has this property.
We need a function, ```equal_sigma1()```, that may collect all the positive integers that fulfill the property described above.
The function receives an upper limit, ```nMax```, will output the total sum of these numbers and its reversed while are less or equal nMax.
Let's see some cases:
```python
equal_sigma1(100) = 0 # There are no numbers.
equal_sigma1(1000) = 1353 # 528 and its revesed 825 were found, 528 + 825 = 1353
equal_sigma1(2000) = 4565 # There are four numbers_: 528 + 825 + 1561 + 1651 = 4565
equal_sigma1(1600) = 2914 # Now we have three numbers: 528 + 825 + 1561 = 2914
equal_sigma1(1561) = 2914
```
The palindromic numbers (like 88, 808, 929), numbers that are equal to its reversed should be discarded.
Happy coding!!
(For more information about the general sigma function see at: https://en.wikipedia.org/wiki/Divisor_function)
|
def f(n):
r = 1 + n
for i in range(2, int(n**0.5) + 1):
if not n % i:
r += i
j = n // i
if i != j:
r += j
return r
s = set()
for i in range(528, 10000):
j = int(str(i)[::-1])
if i != j and f(i) == f(j):
s |= {i, j}
def equal_sigma1(n):
return sum(x for x in s if x <= n)
|
The principal of a school likes to put challenges to the students related with finding words of certain features.
One day she said: "Dear students, the challenge for today is to find a word that has only one vowel and seven consonants but cannot have the letters "y" and "m". I'll give a special award for the first student that finds it." One of the students used his dictionary and spent all the night without sleeping, trying in vain to find the word. The next day, the word had not been found yet.
This student observed that the principal has a pattern in the features for the wanted words:
- The word should have **n** vowels, may be repeated, for example: in "engineering", n = 5.
- The word should have **m** consonants, may be repeated also: in "engineering", m = 6.
- The word should not have some forbidden letters (in an array), forbid_letters
You will be provided with a list of words, WORD_LIST(python/crystal), wordList(javascript), wordList (haskell), $word_list(ruby), and you have to create the function, ```wanted_words()```, that receives the three arguments in the order given above, ```wanted_words(n, m, forbid_list)```and output an array with the word or an array, having the words in the order given in the pre-loaded list, in the case of two or more words were found.
Let's see some cases:
```python
wanted_words(1, 7, ["m", "y"]) == ["strength"]
wanted_words(3, 7, ["m", "y"]) == ['afterwards', 'background', 'photograph', 'successful', 'understand']
```
For cases where no words are found the function will output an empty array.
```python
wanted_words(3, 7, ["a", "s" , "m", "y"]) == []
```
Help our student to win this and the next challenges of the school. He needs to sure about a suspect that he has. That many times there are no solutions for what the principal is asking for.
All words have its letters in lowercase format.
Enjoy it!
|
def wanted_words(vowels, consonants, forbidden):
return [w for w in WORD_LIST
if len(w) == vowels + consonants
and sum(map(w.count, 'aeiou')) == vowels
and not any(c in w for c in forbidden)]
|
The principal of a school likes to put challenges to the students related with finding words of certain features.
One day she said: "Dear students, the challenge for today is to find a word that has only one vowel and seven consonants but cannot have the letters "y" and "m". I'll give a special award for the first student that finds it." One of the students used his dictionary and spent all the night without sleeping, trying in vain to find the word. The next day, the word had not been found yet.
This student observed that the principal has a pattern in the features for the wanted words:
- The word should have **n** vowels, may be repeated, for example: in "engineering", n = 5.
- The word should have **m** consonants, may be repeated also: in "engineering", m = 6.
- The word should not have some forbidden letters (in an array), forbid_letters
You will be provided with a list of words, WORD_LIST(python/crystal), wordList(javascript), wordList (haskell), $word_list(ruby), and you have to create the function, ```wanted_words()```, that receives the three arguments in the order given above, ```wanted_words(n, m, forbid_list)```and output an array with the word or an array, having the words in the order given in the pre-loaded list, in the case of two or more words were found.
Let's see some cases:
```python
wanted_words(1, 7, ["m", "y"]) == ["strength"]
wanted_words(3, 7, ["m", "y"]) == ['afterwards', 'background', 'photograph', 'successful', 'understand']
```
For cases where no words are found the function will output an empty array.
```python
wanted_words(3, 7, ["a", "s" , "m", "y"]) == []
```
Help our student to win this and the next challenges of the school. He needs to sure about a suspect that he has. That many times there are no solutions for what the principal is asking for.
All words have its letters in lowercase format.
Enjoy it!
|
from collections import defaultdict
WORD_INDEX = defaultdict(list)
for w in WORD_LIST:
WORD_INDEX[len(w), sum(map(w.count, 'aeiou'))].append(w)
def wanted_words(vowels, consonants, forbidden):
return [w for w in WORD_INDEX[vowels + consonants, vowels] if not any(c in w for c in forbidden)]
|
The principal of a school likes to put challenges to the students related with finding words of certain features.
One day she said: "Dear students, the challenge for today is to find a word that has only one vowel and seven consonants but cannot have the letters "y" and "m". I'll give a special award for the first student that finds it." One of the students used his dictionary and spent all the night without sleeping, trying in vain to find the word. The next day, the word had not been found yet.
This student observed that the principal has a pattern in the features for the wanted words:
- The word should have **n** vowels, may be repeated, for example: in "engineering", n = 5.
- The word should have **m** consonants, may be repeated also: in "engineering", m = 6.
- The word should not have some forbidden letters (in an array), forbid_letters
You will be provided with a list of words, WORD_LIST(python/crystal), wordList(javascript), wordList (haskell), $word_list(ruby), and you have to create the function, ```wanted_words()```, that receives the three arguments in the order given above, ```wanted_words(n, m, forbid_list)```and output an array with the word or an array, having the words in the order given in the pre-loaded list, in the case of two or more words were found.
Let's see some cases:
```python
wanted_words(1, 7, ["m", "y"]) == ["strength"]
wanted_words(3, 7, ["m", "y"]) == ['afterwards', 'background', 'photograph', 'successful', 'understand']
```
For cases where no words are found the function will output an empty array.
```python
wanted_words(3, 7, ["a", "s" , "m", "y"]) == []
```
Help our student to win this and the next challenges of the school. He needs to sure about a suspect that he has. That many times there are no solutions for what the principal is asking for.
All words have its letters in lowercase format.
Enjoy it!
|
def wanted_words(n, m, forbid_let):
result = []
for word in WORD_LIST:
if set(forbid_let) & set(word):
continue
vowels = sum(1 for c in word if c in "aeiou")
if vowels == n and len(word) == m + n:
result.append(word)
return result
|
The principal of a school likes to put challenges to the students related with finding words of certain features.
One day she said: "Dear students, the challenge for today is to find a word that has only one vowel and seven consonants but cannot have the letters "y" and "m". I'll give a special award for the first student that finds it." One of the students used his dictionary and spent all the night without sleeping, trying in vain to find the word. The next day, the word had not been found yet.
This student observed that the principal has a pattern in the features for the wanted words:
- The word should have **n** vowels, may be repeated, for example: in "engineering", n = 5.
- The word should have **m** consonants, may be repeated also: in "engineering", m = 6.
- The word should not have some forbidden letters (in an array), forbid_letters
You will be provided with a list of words, WORD_LIST(python/crystal), wordList(javascript), wordList (haskell), $word_list(ruby), and you have to create the function, ```wanted_words()```, that receives the three arguments in the order given above, ```wanted_words(n, m, forbid_list)```and output an array with the word or an array, having the words in the order given in the pre-loaded list, in the case of two or more words were found.
Let's see some cases:
```python
wanted_words(1, 7, ["m", "y"]) == ["strength"]
wanted_words(3, 7, ["m", "y"]) == ['afterwards', 'background', 'photograph', 'successful', 'understand']
```
For cases where no words are found the function will output an empty array.
```python
wanted_words(3, 7, ["a", "s" , "m", "y"]) == []
```
Help our student to win this and the next challenges of the school. He needs to sure about a suspect that he has. That many times there are no solutions for what the principal is asking for.
All words have its letters in lowercase format.
Enjoy it!
|
from itertools import groupby
def _breakdown(word):
v = sum(c in 'aeiou' for c in word)
return v, len(word) - v
_WORDS = {k: list(group) for k, group in groupby(sorted(WORD_LIST, key=_breakdown), key=_breakdown)}
def wanted_words(v, c, forbidden):
permitted = lambda word: not any(letter in word for letter in forbidden)
return filter(permitted, _WORDS.get((v,c), []))
|
The principal of a school likes to put challenges to the students related with finding words of certain features.
One day she said: "Dear students, the challenge for today is to find a word that has only one vowel and seven consonants but cannot have the letters "y" and "m". I'll give a special award for the first student that finds it." One of the students used his dictionary and spent all the night without sleeping, trying in vain to find the word. The next day, the word had not been found yet.
This student observed that the principal has a pattern in the features for the wanted words:
- The word should have **n** vowels, may be repeated, for example: in "engineering", n = 5.
- The word should have **m** consonants, may be repeated also: in "engineering", m = 6.
- The word should not have some forbidden letters (in an array), forbid_letters
You will be provided with a list of words, WORD_LIST(python/crystal), wordList(javascript), wordList (haskell), $word_list(ruby), and you have to create the function, ```wanted_words()```, that receives the three arguments in the order given above, ```wanted_words(n, m, forbid_list)```and output an array with the word or an array, having the words in the order given in the pre-loaded list, in the case of two or more words were found.
Let's see some cases:
```python
wanted_words(1, 7, ["m", "y"]) == ["strength"]
wanted_words(3, 7, ["m", "y"]) == ['afterwards', 'background', 'photograph', 'successful', 'understand']
```
For cases where no words are found the function will output an empty array.
```python
wanted_words(3, 7, ["a", "s" , "m", "y"]) == []
```
Help our student to win this and the next challenges of the school. He needs to sure about a suspect that he has. That many times there are no solutions for what the principal is asking for.
All words have its letters in lowercase format.
Enjoy it!
|
def wanted_words(n, m, forbid_let):
f = set(forbid_let)
return [word for word in WORD_LIST if len(word) == n + m and sum(c in 'aeiou' for c in word) == n and f.isdisjoint(word)]
|
The principal of a school likes to put challenges to the students related with finding words of certain features.
One day she said: "Dear students, the challenge for today is to find a word that has only one vowel and seven consonants but cannot have the letters "y" and "m". I'll give a special award for the first student that finds it." One of the students used his dictionary and spent all the night without sleeping, trying in vain to find the word. The next day, the word had not been found yet.
This student observed that the principal has a pattern in the features for the wanted words:
- The word should have **n** vowels, may be repeated, for example: in "engineering", n = 5.
- The word should have **m** consonants, may be repeated also: in "engineering", m = 6.
- The word should not have some forbidden letters (in an array), forbid_letters
You will be provided with a list of words, WORD_LIST(python/crystal), wordList(javascript), wordList (haskell), $word_list(ruby), and you have to create the function, ```wanted_words()```, that receives the three arguments in the order given above, ```wanted_words(n, m, forbid_list)```and output an array with the word or an array, having the words in the order given in the pre-loaded list, in the case of two or more words were found.
Let's see some cases:
```python
wanted_words(1, 7, ["m", "y"]) == ["strength"]
wanted_words(3, 7, ["m", "y"]) == ['afterwards', 'background', 'photograph', 'successful', 'understand']
```
For cases where no words are found the function will output an empty array.
```python
wanted_words(3, 7, ["a", "s" , "m", "y"]) == []
```
Help our student to win this and the next challenges of the school. He needs to sure about a suspect that he has. That many times there are no solutions for what the principal is asking for.
All words have its letters in lowercase format.
Enjoy it!
|
from collections import Counter
def wanted_words(n, m, forbid_let):
result = []
for word in WORD_LIST: # for each word in word list
if len(word) == n + m: # if word length is correct
letters = Counter(word) # create a count of letters
if ( sum(letters[c] for c in "aeiou") == n # if vowel count is correct
and all(c not in word for c in forbid_let) ): # and has no forbidden letters
result.append(word) # add to the results
return result
|
The principal of a school likes to put challenges to the students related with finding words of certain features.
One day she said: "Dear students, the challenge for today is to find a word that has only one vowel and seven consonants but cannot have the letters "y" and "m". I'll give a special award for the first student that finds it." One of the students used his dictionary and spent all the night without sleeping, trying in vain to find the word. The next day, the word had not been found yet.
This student observed that the principal has a pattern in the features for the wanted words:
- The word should have **n** vowels, may be repeated, for example: in "engineering", n = 5.
- The word should have **m** consonants, may be repeated also: in "engineering", m = 6.
- The word should not have some forbidden letters (in an array), forbid_letters
You will be provided with a list of words, WORD_LIST(python/crystal), wordList(javascript), wordList (haskell), $word_list(ruby), and you have to create the function, ```wanted_words()```, that receives the three arguments in the order given above, ```wanted_words(n, m, forbid_list)```and output an array with the word or an array, having the words in the order given in the pre-loaded list, in the case of two or more words were found.
Let's see some cases:
```python
wanted_words(1, 7, ["m", "y"]) == ["strength"]
wanted_words(3, 7, ["m", "y"]) == ['afterwards', 'background', 'photograph', 'successful', 'understand']
```
For cases where no words are found the function will output an empty array.
```python
wanted_words(3, 7, ["a", "s" , "m", "y"]) == []
```
Help our student to win this and the next challenges of the school. He needs to sure about a suspect that he has. That many times there are no solutions for what the principal is asking for.
All words have its letters in lowercase format.
Enjoy it!
|
from collections import defaultdict
from itertools import filterfalse
is_vowel = set("aeiou").__contains__
result = defaultdict(lambda:defaultdict(list))
for w in WORD_LIST:
nb_v = sum(map(is_vowel, w))
nb_c = len(w) - nb_v
result[nb_v][nb_c].append(w)
def wanted_words(n, m, forbid_let):
return list(filterfalse(set(forbid_let).intersection, result.get(n, {}).get(m, [])))
|
The principal of a school likes to put challenges to the students related with finding words of certain features.
One day she said: "Dear students, the challenge for today is to find a word that has only one vowel and seven consonants but cannot have the letters "y" and "m". I'll give a special award for the first student that finds it." One of the students used his dictionary and spent all the night without sleeping, trying in vain to find the word. The next day, the word had not been found yet.
This student observed that the principal has a pattern in the features for the wanted words:
- The word should have **n** vowels, may be repeated, for example: in "engineering", n = 5.
- The word should have **m** consonants, may be repeated also: in "engineering", m = 6.
- The word should not have some forbidden letters (in an array), forbid_letters
You will be provided with a list of words, WORD_LIST(python/crystal), wordList(javascript), wordList (haskell), $word_list(ruby), and you have to create the function, ```wanted_words()```, that receives the three arguments in the order given above, ```wanted_words(n, m, forbid_list)```and output an array with the word or an array, having the words in the order given in the pre-loaded list, in the case of two or more words were found.
Let's see some cases:
```python
wanted_words(1, 7, ["m", "y"]) == ["strength"]
wanted_words(3, 7, ["m", "y"]) == ['afterwards', 'background', 'photograph', 'successful', 'understand']
```
For cases where no words are found the function will output an empty array.
```python
wanted_words(3, 7, ["a", "s" , "m", "y"]) == []
```
Help our student to win this and the next challenges of the school. He needs to sure about a suspect that he has. That many times there are no solutions for what the principal is asking for.
All words have its letters in lowercase format.
Enjoy it!
|
def wanted_words(n, m, forbid_let):
import re
vov = "[aeiou]"
cons= "[qwrtpysdfghjklzxcvbnm]"
fb = "[" + ''.join(forbid_let) + "]"
return [word for word in WORD_LIST if len(re.findall(vov, word))==n and len(re.findall(cons, word))==m and len(re.findall(fb, word))==0]
|
The principal of a school likes to put challenges to the students related with finding words of certain features.
One day she said: "Dear students, the challenge for today is to find a word that has only one vowel and seven consonants but cannot have the letters "y" and "m". I'll give a special award for the first student that finds it." One of the students used his dictionary and spent all the night without sleeping, trying in vain to find the word. The next day, the word had not been found yet.
This student observed that the principal has a pattern in the features for the wanted words:
- The word should have **n** vowels, may be repeated, for example: in "engineering", n = 5.
- The word should have **m** consonants, may be repeated also: in "engineering", m = 6.
- The word should not have some forbidden letters (in an array), forbid_letters
You will be provided with a list of words, WORD_LIST(python/crystal), wordList(javascript), wordList (haskell), $word_list(ruby), and you have to create the function, ```wanted_words()```, that receives the three arguments in the order given above, ```wanted_words(n, m, forbid_list)```and output an array with the word or an array, having the words in the order given in the pre-loaded list, in the case of two or more words were found.
Let's see some cases:
```python
wanted_words(1, 7, ["m", "y"]) == ["strength"]
wanted_words(3, 7, ["m", "y"]) == ['afterwards', 'background', 'photograph', 'successful', 'understand']
```
For cases where no words are found the function will output an empty array.
```python
wanted_words(3, 7, ["a", "s" , "m", "y"]) == []
```
Help our student to win this and the next challenges of the school. He needs to sure about a suspect that he has. That many times there are no solutions for what the principal is asking for.
All words have its letters in lowercase format.
Enjoy it!
|
wanted_words = lambda n, m, f: [i for i in WORD_LIST if len([j for j in i if j in 'aeiou'])==n and len([j for j in i if not j in 'aeiou'])==m
and not any(k in i for k in f)]
|
The principal of a school likes to put challenges to the students related with finding words of certain features.
One day she said: "Dear students, the challenge for today is to find a word that has only one vowel and seven consonants but cannot have the letters "y" and "m". I'll give a special award for the first student that finds it." One of the students used his dictionary and spent all the night without sleeping, trying in vain to find the word. The next day, the word had not been found yet.
This student observed that the principal has a pattern in the features for the wanted words:
- The word should have **n** vowels, may be repeated, for example: in "engineering", n = 5.
- The word should have **m** consonants, may be repeated also: in "engineering", m = 6.
- The word should not have some forbidden letters (in an array), forbid_letters
You will be provided with a list of words, WORD_LIST(python/crystal), wordList(javascript), wordList (haskell), $word_list(ruby), and you have to create the function, ```wanted_words()```, that receives the three arguments in the order given above, ```wanted_words(n, m, forbid_list)```and output an array with the word or an array, having the words in the order given in the pre-loaded list, in the case of two or more words were found.
Let's see some cases:
```python
wanted_words(1, 7, ["m", "y"]) == ["strength"]
wanted_words(3, 7, ["m", "y"]) == ['afterwards', 'background', 'photograph', 'successful', 'understand']
```
For cases where no words are found the function will output an empty array.
```python
wanted_words(3, 7, ["a", "s" , "m", "y"]) == []
```
Help our student to win this and the next challenges of the school. He needs to sure about a suspect that he has. That many times there are no solutions for what the principal is asking for.
All words have its letters in lowercase format.
Enjoy it!
|
D = {w:(len([c for c in w if c in 'aeiou']), len([c for c in w if c not in 'aeiou'])) for w in WORD_LIST}
def wanted_words(n, m, forbid_let):
return [w for w in WORD_LIST if D[w] == (n, m) and not [c for c in forbid_let if c in w]]
|
The principal of a school likes to put challenges to the students related with finding words of certain features.
One day she said: "Dear students, the challenge for today is to find a word that has only one vowel and seven consonants but cannot have the letters "y" and "m". I'll give a special award for the first student that finds it." One of the students used his dictionary and spent all the night without sleeping, trying in vain to find the word. The next day, the word had not been found yet.
This student observed that the principal has a pattern in the features for the wanted words:
- The word should have **n** vowels, may be repeated, for example: in "engineering", n = 5.
- The word should have **m** consonants, may be repeated also: in "engineering", m = 6.
- The word should not have some forbidden letters (in an array), forbid_letters
You will be provided with a list of words, WORD_LIST(python/crystal), wordList(javascript), wordList (haskell), $word_list(ruby), and you have to create the function, ```wanted_words()```, that receives the three arguments in the order given above, ```wanted_words(n, m, forbid_list)```and output an array with the word or an array, having the words in the order given in the pre-loaded list, in the case of two or more words were found.
Let's see some cases:
```python
wanted_words(1, 7, ["m", "y"]) == ["strength"]
wanted_words(3, 7, ["m", "y"]) == ['afterwards', 'background', 'photograph', 'successful', 'understand']
```
For cases where no words are found the function will output an empty array.
```python
wanted_words(3, 7, ["a", "s" , "m", "y"]) == []
```
Help our student to win this and the next challenges of the school. He needs to sure about a suspect that he has. That many times there are no solutions for what the principal is asking for.
All words have its letters in lowercase format.
Enjoy it!
|
import re
def wanted_words(n, m, forbid_let):
return [word for word in WORD_LIST if len(word) == n + m and len(re.findall("[aeiou]", word)) == n and not re.findall("[" + "".join(forbid_let) + "]", word)]
|
Complete the method that takes a sequence of objects with two keys each: country or state, and capital. Keys may be symbols or strings.
The method should return an array of sentences declaring the state or country and its capital.
## Examples
```python
[{'state': 'Maine', 'capital': 'Augusta'}] --> ["The capital of Maine is Augusta"]
[{'country' : 'Spain', 'capital' : 'Madrid'}] --> ["The capital of Spain is Madrid"]
[{"state" : 'Maine', 'capital': 'Augusta'}, {'country': 'Spain', "capital" : "Madrid"}] --> ["The capital of Maine is Augusta", "The capital of Spain is Madrid"]
```
|
def capital(capitals):
return [f"The capital of {c.get('state') or c['country']} is {c['capital']}" for c in capitals]
|
Complete the method that takes a sequence of objects with two keys each: country or state, and capital. Keys may be symbols or strings.
The method should return an array of sentences declaring the state or country and its capital.
## Examples
```python
[{'state': 'Maine', 'capital': 'Augusta'}] --> ["The capital of Maine is Augusta"]
[{'country' : 'Spain', 'capital' : 'Madrid'}] --> ["The capital of Spain is Madrid"]
[{"state" : 'Maine', 'capital': 'Augusta'}, {'country': 'Spain', "capital" : "Madrid"}] --> ["The capital of Maine is Augusta", "The capital of Spain is Madrid"]
```
|
def capital(capitals):
ans = []
for each in capitals:
a = each.get('state', '')
b = each.get('country', '')
c = each.get('capital')
ans.append('The capital of {}{} is {}'.format(a,b,c))
return ans
|
Complete the method that takes a sequence of objects with two keys each: country or state, and capital. Keys may be symbols or strings.
The method should return an array of sentences declaring the state or country and its capital.
## Examples
```python
[{'state': 'Maine', 'capital': 'Augusta'}] --> ["The capital of Maine is Augusta"]
[{'country' : 'Spain', 'capital' : 'Madrid'}] --> ["The capital of Spain is Madrid"]
[{"state" : 'Maine', 'capital': 'Augusta'}, {'country': 'Spain', "capital" : "Madrid"}] --> ["The capital of Maine is Augusta", "The capital of Spain is Madrid"]
```
|
def capital(capitals):
return ["The capital of {} is {}".format(*x.values()) for x in capitals]
|
Complete the method that takes a sequence of objects with two keys each: country or state, and capital. Keys may be symbols or strings.
The method should return an array of sentences declaring the state or country and its capital.
## Examples
```python
[{'state': 'Maine', 'capital': 'Augusta'}] --> ["The capital of Maine is Augusta"]
[{'country' : 'Spain', 'capital' : 'Madrid'}] --> ["The capital of Spain is Madrid"]
[{"state" : 'Maine', 'capital': 'Augusta'}, {'country': 'Spain', "capital" : "Madrid"}] --> ["The capital of Maine is Augusta", "The capital of Spain is Madrid"]
```
|
def capital(capitals):
return [f"The capital of {d['state'] if 'state' in d else d['country'] } is {d['capital']}" for d in capitals]
|
Complete the method that takes a sequence of objects with two keys each: country or state, and capital. Keys may be symbols or strings.
The method should return an array of sentences declaring the state or country and its capital.
## Examples
```python
[{'state': 'Maine', 'capital': 'Augusta'}] --> ["The capital of Maine is Augusta"]
[{'country' : 'Spain', 'capital' : 'Madrid'}] --> ["The capital of Spain is Madrid"]
[{"state" : 'Maine', 'capital': 'Augusta'}, {'country': 'Spain', "capital" : "Madrid"}] --> ["The capital of Maine is Augusta", "The capital of Spain is Madrid"]
```
|
def capital(capitals):
list1 = []
for i in capitals:
a = list(i.values())
print(a)
list1.append("The capital of " + a[0] + " is " + a[1])
return list1
|
Complete the method that takes a sequence of objects with two keys each: country or state, and capital. Keys may be symbols or strings.
The method should return an array of sentences declaring the state or country and its capital.
## Examples
```python
[{'state': 'Maine', 'capital': 'Augusta'}] --> ["The capital of Maine is Augusta"]
[{'country' : 'Spain', 'capital' : 'Madrid'}] --> ["The capital of Spain is Madrid"]
[{"state" : 'Maine', 'capital': 'Augusta'}, {'country': 'Spain', "capital" : "Madrid"}] --> ["The capital of Maine is Augusta", "The capital of Spain is Madrid"]
```
|
def capital(capitals):
return list(map(lambda val: 'The capital of ' + (val.get('state') or val.get('country')) + ' is ' + val["capital"],
capitals))
|
Complete the method that takes a sequence of objects with two keys each: country or state, and capital. Keys may be symbols or strings.
The method should return an array of sentences declaring the state or country and its capital.
## Examples
```python
[{'state': 'Maine', 'capital': 'Augusta'}] --> ["The capital of Maine is Augusta"]
[{'country' : 'Spain', 'capital' : 'Madrid'}] --> ["The capital of Spain is Madrid"]
[{"state" : 'Maine', 'capital': 'Augusta'}, {'country': 'Spain', "capital" : "Madrid"}] --> ["The capital of Maine is Augusta", "The capital of Spain is Madrid"]
```
|
def capital(capitals):
# your code here
q = []
lst = []
p = len(capitals)
for i in capitals:
for key,value in i.items():
var1 = value
q.append(var1)
lst2 = []
for x,y in enumerate(q,1):
lst.append(y)
if x % 2 == 0:
lst2.append("The capital of {} is {}".format(lst[0],lst[1]))
lst.clear()
return lst2
|
Complete the method that takes a sequence of objects with two keys each: country or state, and capital. Keys may be symbols or strings.
The method should return an array of sentences declaring the state or country and its capital.
## Examples
```python
[{'state': 'Maine', 'capital': 'Augusta'}] --> ["The capital of Maine is Augusta"]
[{'country' : 'Spain', 'capital' : 'Madrid'}] --> ["The capital of Spain is Madrid"]
[{"state" : 'Maine', 'capital': 'Augusta'}, {'country': 'Spain', "capital" : "Madrid"}] --> ["The capital of Maine is Augusta", "The capital of Spain is Madrid"]
```
|
def capital(capitals):
return [f"The capital of {s.get('state') or s.get('country')} is {s.get('capital')}" for s in capitals]
|
Complete the method that takes a sequence of objects with two keys each: country or state, and capital. Keys may be symbols or strings.
The method should return an array of sentences declaring the state or country and its capital.
## Examples
```python
[{'state': 'Maine', 'capital': 'Augusta'}] --> ["The capital of Maine is Augusta"]
[{'country' : 'Spain', 'capital' : 'Madrid'}] --> ["The capital of Spain is Madrid"]
[{"state" : 'Maine', 'capital': 'Augusta'}, {'country': 'Spain', "capital" : "Madrid"}] --> ["The capital of Maine is Augusta", "The capital of Spain is Madrid"]
```
|
def capital(capitals):
result= []
for i in capitals:
if "country" in list(i.keys()):
country_State = "country"
else:
country_State = "state"
result.append("The capital of " + i[country_State] + " is " + i["capital"])
return result
|
Complete the method that takes a sequence of objects with two keys each: country or state, and capital. Keys may be symbols or strings.
The method should return an array of sentences declaring the state or country and its capital.
## Examples
```python
[{'state': 'Maine', 'capital': 'Augusta'}] --> ["The capital of Maine is Augusta"]
[{'country' : 'Spain', 'capital' : 'Madrid'}] --> ["The capital of Spain is Madrid"]
[{"state" : 'Maine', 'capital': 'Augusta'}, {'country': 'Spain', "capital" : "Madrid"}] --> ["The capital of Maine is Augusta", "The capital of Spain is Madrid"]
```
|
def capital(capitals):
output = []
i = 0
for key1, key2 in capitals:
if key1 == "country":
output.append(
f"The capital of {capitals[i]['country']} is {capitals[i]['capital']}")
if key1 == "state":
output.append(
f"The capital of {capitals[i]['state']} is {capitals[i]['capital']}")
i += 1
return output
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.