Datasets:

inputs
stringlengths
50
14k
targets
stringlengths
4
655k
Your task is to implement a function that takes one or more dictionaries and combines them in one result dictionary. The keys in the given dictionaries can overlap. In that case you should combine all source values in an array. Duplicate values should be preserved. Here is an example: ```cs var source1 = new Dictionary{{"A", 1}, {"B", 2}}; var source2 = new Dictionary{{"A", 3}}; Dictionary result = DictionaryMerger.Merge(source1, source2); // result should have this content: {{"A", [1, 3]}, {"B", [2]}} ``` ```python source1 = {"A": 1, "B": 2} source2 = {"A": 3} result = merge(source1, source2); // result should have this content: {"A": [1, 3]}, "B": [2]} ``` You can assume that only valid dictionaries are passed to your function. The number of given dictionaries might be large. So take care about performance.
def merge(*dcts): return {k: [dct[k] for dct in dcts if k in dct] for dct in dcts for k in dct}
Your task is to implement a function that takes one or more dictionaries and combines them in one result dictionary. The keys in the given dictionaries can overlap. In that case you should combine all source values in an array. Duplicate values should be preserved. Here is an example: ```cs var source1 = new Dictionary{{"A", 1}, {"B", 2}}; var source2 = new Dictionary{{"A", 3}}; Dictionary result = DictionaryMerger.Merge(source1, source2); // result should have this content: {{"A", [1, 3]}, {"B", [2]}} ``` ```python source1 = {"A": 1, "B": 2} source2 = {"A": 3} result = merge(source1, source2); // result should have this content: {"A": [1, 3]}, "B": [2]} ``` You can assume that only valid dictionaries are passed to your function. The number of given dictionaries might be large. So take care about performance.
def merge(*dicts): merged = {} for dict in dicts: for k, v in dict.items(): merged.setdefault(k, []).append(v) return merged
Your task is to implement a function that takes one or more dictionaries and combines them in one result dictionary. The keys in the given dictionaries can overlap. In that case you should combine all source values in an array. Duplicate values should be preserved. Here is an example: ```cs var source1 = new Dictionary{{"A", 1}, {"B", 2}}; var source2 = new Dictionary{{"A", 3}}; Dictionary result = DictionaryMerger.Merge(source1, source2); // result should have this content: {{"A", [1, 3]}, {"B", [2]}} ``` ```python source1 = {"A": 1, "B": 2} source2 = {"A": 3} result = merge(source1, source2); // result should have this content: {"A": [1, 3]}, "B": [2]} ``` You can assume that only valid dictionaries are passed to your function. The number of given dictionaries might be large. So take care about performance.
from collections import defaultdict def merge(*dcts): result = defaultdict(list) for dct in dcts: for k, v in list(dct.items()): result[k].append(v) return result
Your task is to implement a function that takes one or more dictionaries and combines them in one result dictionary. The keys in the given dictionaries can overlap. In that case you should combine all source values in an array. Duplicate values should be preserved. Here is an example: ```cs var source1 = new Dictionary{{"A", 1}, {"B", 2}}; var source2 = new Dictionary{{"A", 3}}; Dictionary result = DictionaryMerger.Merge(source1, source2); // result should have this content: {{"A", [1, 3]}, {"B", [2]}} ``` ```python source1 = {"A": 1, "B": 2} source2 = {"A": 3} result = merge(source1, source2); // result should have this content: {"A": [1, 3]}, "B": [2]} ``` You can assume that only valid dictionaries are passed to your function. The number of given dictionaries might be large. So take care about performance.
def merge(*dicts): r = {} for d in dicts: for k, v in d.items(): if k in r: r[k].append(v) else: r[k] = [v] return r
John has invited some friends. His list is: ``` s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill"; ``` Could you make a program that - makes this string uppercase - gives it sorted in alphabetical order by last name. When the last names are the same, sort them by first name. Last name and first name of a guest come in the result between parentheses separated by a comma. So the result of function `meeting(s)` will be: ``` "(CORWILL, ALFRED)(CORWILL, FRED)(CORWILL, RAPHAEL)(CORWILL, WILFRED)(TORNBULL, BARNEY)(TORNBULL, BETTY)(TORNBULL, BJON)" ``` It can happen that in two distinct families with the same family name two people have the same first name too. # Notes - You can see another examples in the "Sample tests".
def meeting(s): return ''.join(sorted('({1}, {0})'.format(*(x.split(':'))) for x in s.upper().split(';')))
John has invited some friends. His list is: ``` s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill"; ``` Could you make a program that - makes this string uppercase - gives it sorted in alphabetical order by last name. When the last names are the same, sort them by first name. Last name and first name of a guest come in the result between parentheses separated by a comma. So the result of function `meeting(s)` will be: ``` "(CORWILL, ALFRED)(CORWILL, FRED)(CORWILL, RAPHAEL)(CORWILL, WILFRED)(TORNBULL, BARNEY)(TORNBULL, BETTY)(TORNBULL, BJON)" ``` It can happen that in two distinct families with the same family name two people have the same first name too. # Notes - You can see another examples in the "Sample tests".
def meeting(s): s = s.upper() s = s.split(';') array = [] string = "" for i in s: i = i.split(':') string = '('+i[1]+', '+i[0]+')' array.append(string) array.sort() output = "" for j in array: output += j return output
John has invited some friends. His list is: ``` s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill"; ``` Could you make a program that - makes this string uppercase - gives it sorted in alphabetical order by last name. When the last names are the same, sort them by first name. Last name and first name of a guest come in the result between parentheses separated by a comma. So the result of function `meeting(s)` will be: ``` "(CORWILL, ALFRED)(CORWILL, FRED)(CORWILL, RAPHAEL)(CORWILL, WILFRED)(TORNBULL, BARNEY)(TORNBULL, BETTY)(TORNBULL, BJON)" ``` It can happen that in two distinct families with the same family name two people have the same first name too. # Notes - You can see another examples in the "Sample tests".
def meeting(s): return ''.join(f'({a}, {b})' for a, b in sorted(name.split(':')[::-1] for name in s.upper().split(';')))
John has invited some friends. His list is: ``` s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill"; ``` Could you make a program that - makes this string uppercase - gives it sorted in alphabetical order by last name. When the last names are the same, sort them by first name. Last name and first name of a guest come in the result between parentheses separated by a comma. So the result of function `meeting(s)` will be: ``` "(CORWILL, ALFRED)(CORWILL, FRED)(CORWILL, RAPHAEL)(CORWILL, WILFRED)(TORNBULL, BARNEY)(TORNBULL, BETTY)(TORNBULL, BJON)" ``` It can happen that in two distinct families with the same family name two people have the same first name too. # Notes - You can see another examples in the "Sample tests".
def meeting(s): names = s.upper().split(';') return ''.join(sorted('({1}, {0})'.format(*(n.split(':'))) for n in names))
John has invited some friends. His list is: ``` s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill"; ``` Could you make a program that - makes this string uppercase - gives it sorted in alphabetical order by last name. When the last names are the same, sort them by first name. Last name and first name of a guest come in the result between parentheses separated by a comma. So the result of function `meeting(s)` will be: ``` "(CORWILL, ALFRED)(CORWILL, FRED)(CORWILL, RAPHAEL)(CORWILL, WILFRED)(TORNBULL, BARNEY)(TORNBULL, BETTY)(TORNBULL, BJON)" ``` It can happen that in two distinct families with the same family name two people have the same first name too. # Notes - You can see another examples in the "Sample tests".
meeting=lambda s:''.join(sorted('(%s, %s)'%tuple(e.split(':')[::-1])for e in s.upper().split(';')))
John has invited some friends. His list is: ``` s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill"; ``` Could you make a program that - makes this string uppercase - gives it sorted in alphabetical order by last name. When the last names are the same, sort them by first name. Last name and first name of a guest come in the result between parentheses separated by a comma. So the result of function `meeting(s)` will be: ``` "(CORWILL, ALFRED)(CORWILL, FRED)(CORWILL, RAPHAEL)(CORWILL, WILFRED)(TORNBULL, BARNEY)(TORNBULL, BETTY)(TORNBULL, BJON)" ``` It can happen that in two distinct families with the same family name two people have the same first name too. # Notes - You can see another examples in the "Sample tests".
import re def meeting(s): return "".join( sorted( re.sub("(\w+):(\w+);?", r"(\2, \1);", s.upper()) .split(";") ) )
John has invited some friends. His list is: ``` s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill"; ``` Could you make a program that - makes this string uppercase - gives it sorted in alphabetical order by last name. When the last names are the same, sort them by first name. Last name and first name of a guest come in the result between parentheses separated by a comma. So the result of function `meeting(s)` will be: ``` "(CORWILL, ALFRED)(CORWILL, FRED)(CORWILL, RAPHAEL)(CORWILL, WILFRED)(TORNBULL, BARNEY)(TORNBULL, BETTY)(TORNBULL, BJON)" ``` It can happen that in two distinct families with the same family name two people have the same first name too. # Notes - You can see another examples in the "Sample tests".
def meeting(s): return ''.join(sorted(('({1}, {0})'.format(*pair.split(':')) for pair in s.upper().split(';'))))
John has invited some friends. His list is: ``` s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill"; ``` Could you make a program that - makes this string uppercase - gives it sorted in alphabetical order by last name. When the last names are the same, sort them by first name. Last name and first name of a guest come in the result between parentheses separated by a comma. So the result of function `meeting(s)` will be: ``` "(CORWILL, ALFRED)(CORWILL, FRED)(CORWILL, RAPHAEL)(CORWILL, WILFRED)(TORNBULL, BARNEY)(TORNBULL, BETTY)(TORNBULL, BJON)" ``` It can happen that in two distinct families with the same family name two people have the same first name too. # Notes - You can see another examples in the "Sample tests".
from functools import reduce def meeting(s): people = [ i.split(":")[::-1] for i in s.upper().split(";") ] people.sort(key=lambda x: x[0]+" "+x[1]) return reduce(lambda acc, x: acc+"("+x[0]+", "+x[1]+")", people, "")
John has invited some friends. His list is: ``` s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill"; ``` Could you make a program that - makes this string uppercase - gives it sorted in alphabetical order by last name. When the last names are the same, sort them by first name. Last name and first name of a guest come in the result between parentheses separated by a comma. So the result of function `meeting(s)` will be: ``` "(CORWILL, ALFRED)(CORWILL, FRED)(CORWILL, RAPHAEL)(CORWILL, WILFRED)(TORNBULL, BARNEY)(TORNBULL, BETTY)(TORNBULL, BJON)" ``` It can happen that in two distinct families with the same family name two people have the same first name too. # Notes - You can see another examples in the "Sample tests".
from functools import cmp_to_key def meeting(s): def comp(a, b): if a[1] == b[1]: return -1 if a[0] < b[0] else 1 else: return -1 if a[1] < b[1] else 1 w = map(lambda x : x.split(":"), s.upper().split(";")) u = sorted(w, key = cmp_to_key(comp)) return "".join(map(lambda a : "(" + a[1] + ", " + a[0] + ")", u))
John has invited some friends. His list is: ``` s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill"; ``` Could you make a program that - makes this string uppercase - gives it sorted in alphabetical order by last name. When the last names are the same, sort them by first name. Last name and first name of a guest come in the result between parentheses separated by a comma. So the result of function `meeting(s)` will be: ``` "(CORWILL, ALFRED)(CORWILL, FRED)(CORWILL, RAPHAEL)(CORWILL, WILFRED)(TORNBULL, BARNEY)(TORNBULL, BETTY)(TORNBULL, BJON)" ``` It can happen that in two distinct families with the same family name two people have the same first name too. # Notes - You can see another examples in the "Sample tests".
meeting = lambda s: "".join("({}, {})".format(ln, fn) for ln, fn in sorted(p.split(":")[::-1] for p in s.upper().split(";")))
*You are a composer who just wrote an awesome piece of music. Now it's time to present it to a band that will perform your piece, but there's a problem! The singers vocal range doesn't stretch as your piece requires, and you have to transpose the whole piece.* # Your task Given a list of notes (represented as strings) and an interval, output a list of transposed notes in *sharp* notation. **Input notes may be represented both in flat and sharp notations (more on that below).** **For this kata, assume that input is always valid and the song is *at least* 1 note long.** **Assume that interval is an integer between -12 and 12.** # Short intro to musical notation Transposing a single note means shifting its value by a certain interval. The notes are as following: A, A#, B, C, C#, D, D#, E, F, F#, G, G#. This is using *sharp* notation, where '#' after a note means that it is one step higher than the note. So A# is one step higher than A. An alternative to sharp notation is the *flat* notation: A, Bb, B, C, Db, D, Eb, E, F, Gb, G, Ab. The 'b' after a note means that it is one step lower than the note. # Examples ['G'] -> 5 steps -> ['C'] ['Db'] -> -4 steps -> ['A#'] ['E', 'F'] -> 1 step -> ['F', 'F#']
def transpose(song, interval): altern = {"Bb": "A#", "Db": "C#", "Eb": "D#", "Gb": "F#", "Ab": "G#"} notes = ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#'] return [notes[(notes.index(altern.get(i, i)) + interval) % 12] for i in song]
*You are a composer who just wrote an awesome piece of music. Now it's time to present it to a band that will perform your piece, but there's a problem! The singers vocal range doesn't stretch as your piece requires, and you have to transpose the whole piece.* # Your task Given a list of notes (represented as strings) and an interval, output a list of transposed notes in *sharp* notation. **Input notes may be represented both in flat and sharp notations (more on that below).** **For this kata, assume that input is always valid and the song is *at least* 1 note long.** **Assume that interval is an integer between -12 and 12.** # Short intro to musical notation Transposing a single note means shifting its value by a certain interval. The notes are as following: A, A#, B, C, C#, D, D#, E, F, F#, G, G#. This is using *sharp* notation, where '#' after a note means that it is one step higher than the note. So A# is one step higher than A. An alternative to sharp notation is the *flat* notation: A, Bb, B, C, Db, D, Eb, E, F, Gb, G, Ab. The 'b' after a note means that it is one step lower than the note. # Examples ['G'] -> 5 steps -> ['C'] ['Db'] -> -4 steps -> ['A#'] ['E', 'F'] -> 1 step -> ['F', 'F#']
table = "A Bb B C Db D Eb E F Gb G Ab".split() table += "A A# B C C# D D# E F F# G G#".split() * 3 def transpose(song, interval): return [table[table.index(note) + interval%12 + 12] for note in song]
*You are a composer who just wrote an awesome piece of music. Now it's time to present it to a band that will perform your piece, but there's a problem! The singers vocal range doesn't stretch as your piece requires, and you have to transpose the whole piece.* # Your task Given a list of notes (represented as strings) and an interval, output a list of transposed notes in *sharp* notation. **Input notes may be represented both in flat and sharp notations (more on that below).** **For this kata, assume that input is always valid and the song is *at least* 1 note long.** **Assume that interval is an integer between -12 and 12.** # Short intro to musical notation Transposing a single note means shifting its value by a certain interval. The notes are as following: A, A#, B, C, C#, D, D#, E, F, F#, G, G#. This is using *sharp* notation, where '#' after a note means that it is one step higher than the note. So A# is one step higher than A. An alternative to sharp notation is the *flat* notation: A, Bb, B, C, Db, D, Eb, E, F, Gb, G, Ab. The 'b' after a note means that it is one step lower than the note. # Examples ['G'] -> 5 steps -> ['C'] ['Db'] -> -4 steps -> ['A#'] ['E', 'F'] -> 1 step -> ['F', 'F#']
SHARP = "A, A#, B, C, C#, D, D#, E, F, F#, G, G#".split(", ") FLAT = "A, Bb, B, C, Db, D, Eb, E, F, Gb, G, Ab".split(", ") REVERSED_INDEX = {**{note: i for i, note in enumerate(SHARP)}, **{note: i for i, note in enumerate(FLAT)}} def transpose(song, interval): return [SHARP[(REVERSED_INDEX[note] + interval) % 12] for note in song]
*You are a composer who just wrote an awesome piece of music. Now it's time to present it to a band that will perform your piece, but there's a problem! The singers vocal range doesn't stretch as your piece requires, and you have to transpose the whole piece.* # Your task Given a list of notes (represented as strings) and an interval, output a list of transposed notes in *sharp* notation. **Input notes may be represented both in flat and sharp notations (more on that below).** **For this kata, assume that input is always valid and the song is *at least* 1 note long.** **Assume that interval is an integer between -12 and 12.** # Short intro to musical notation Transposing a single note means shifting its value by a certain interval. The notes are as following: A, A#, B, C, C#, D, D#, E, F, F#, G, G#. This is using *sharp* notation, where '#' after a note means that it is one step higher than the note. So A# is one step higher than A. An alternative to sharp notation is the *flat* notation: A, Bb, B, C, Db, D, Eb, E, F, Gb, G, Ab. The 'b' after a note means that it is one step lower than the note. # Examples ['G'] -> 5 steps -> ['C'] ['Db'] -> -4 steps -> ['A#'] ['E', 'F'] -> 1 step -> ['F', 'F#']
def transpose(song, interval): sharp = ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#'] flat = ['A', 'Bb', 'B', 'C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab'] return [sharp[(12 + (sharp.index(nt) if nt in sharp else flat.index(nt)) + interval) % 12] for nt in song]
*You are a composer who just wrote an awesome piece of music. Now it's time to present it to a band that will perform your piece, but there's a problem! The singers vocal range doesn't stretch as your piece requires, and you have to transpose the whole piece.* # Your task Given a list of notes (represented as strings) and an interval, output a list of transposed notes in *sharp* notation. **Input notes may be represented both in flat and sharp notations (more on that below).** **For this kata, assume that input is always valid and the song is *at least* 1 note long.** **Assume that interval is an integer between -12 and 12.** # Short intro to musical notation Transposing a single note means shifting its value by a certain interval. The notes are as following: A, A#, B, C, C#, D, D#, E, F, F#, G, G#. This is using *sharp* notation, where '#' after a note means that it is one step higher than the note. So A# is one step higher than A. An alternative to sharp notation is the *flat* notation: A, Bb, B, C, Db, D, Eb, E, F, Gb, G, Ab. The 'b' after a note means that it is one step lower than the note. # Examples ['G'] -> 5 steps -> ['C'] ['Db'] -> -4 steps -> ['A#'] ['E', 'F'] -> 1 step -> ['F', 'F#']
def transpose(song, interval): sharp = ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#'] flat = ['A', 'Bb', 'B', 'C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab'] result = [] for note in song: if note in sharp: result.append(sharp[(sharp.index(note) + interval) % 12]) else: result.append(sharp[(flat.index(note) + interval) % 12]) return result
*You are a composer who just wrote an awesome piece of music. Now it's time to present it to a band that will perform your piece, but there's a problem! The singers vocal range doesn't stretch as your piece requires, and you have to transpose the whole piece.* # Your task Given a list of notes (represented as strings) and an interval, output a list of transposed notes in *sharp* notation. **Input notes may be represented both in flat and sharp notations (more on that below).** **For this kata, assume that input is always valid and the song is *at least* 1 note long.** **Assume that interval is an integer between -12 and 12.** # Short intro to musical notation Transposing a single note means shifting its value by a certain interval. The notes are as following: A, A#, B, C, C#, D, D#, E, F, F#, G, G#. This is using *sharp* notation, where '#' after a note means that it is one step higher than the note. So A# is one step higher than A. An alternative to sharp notation is the *flat* notation: A, Bb, B, C, Db, D, Eb, E, F, Gb, G, Ab. The 'b' after a note means that it is one step lower than the note. # Examples ['G'] -> 5 steps -> ['C'] ['Db'] -> -4 steps -> ['A#'] ['E', 'F'] -> 1 step -> ['F', 'F#']
def transpose(song, interval): notes = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "Bb", "B", "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab"] return [ notes[(12+notes.index(n)+interval)%12] for n in song ]
*You are a composer who just wrote an awesome piece of music. Now it's time to present it to a band that will perform your piece, but there's a problem! The singers vocal range doesn't stretch as your piece requires, and you have to transpose the whole piece.* # Your task Given a list of notes (represented as strings) and an interval, output a list of transposed notes in *sharp* notation. **Input notes may be represented both in flat and sharp notations (more on that below).** **For this kata, assume that input is always valid and the song is *at least* 1 note long.** **Assume that interval is an integer between -12 and 12.** # Short intro to musical notation Transposing a single note means shifting its value by a certain interval. The notes are as following: A, A#, B, C, C#, D, D#, E, F, F#, G, G#. This is using *sharp* notation, where '#' after a note means that it is one step higher than the note. So A# is one step higher than A. An alternative to sharp notation is the *flat* notation: A, Bb, B, C, Db, D, Eb, E, F, Gb, G, Ab. The 'b' after a note means that it is one step lower than the note. # Examples ['G'] -> 5 steps -> ['C'] ['Db'] -> -4 steps -> ['A#'] ['E', 'F'] -> 1 step -> ['F', 'F#']
transpose=lambda s, i: (lambda sharp,flat: [sharp[(flat.index(n)+i+12)%12] if n in flat else sharp[(sharp.index(n)+i+12)%12] for n in s])(["A","A#","B","C","C#","D","D#","E","F","F#","G","G#"],["A","Bb","B","C","Db","D","Eb","E","F","Gb","G","Ab"])
*You are a composer who just wrote an awesome piece of music. Now it's time to present it to a band that will perform your piece, but there's a problem! The singers vocal range doesn't stretch as your piece requires, and you have to transpose the whole piece.* # Your task Given a list of notes (represented as strings) and an interval, output a list of transposed notes in *sharp* notation. **Input notes may be represented both in flat and sharp notations (more on that below).** **For this kata, assume that input is always valid and the song is *at least* 1 note long.** **Assume that interval is an integer between -12 and 12.** # Short intro to musical notation Transposing a single note means shifting its value by a certain interval. The notes are as following: A, A#, B, C, C#, D, D#, E, F, F#, G, G#. This is using *sharp* notation, where '#' after a note means that it is one step higher than the note. So A# is one step higher than A. An alternative to sharp notation is the *flat* notation: A, Bb, B, C, Db, D, Eb, E, F, Gb, G, Ab. The 'b' after a note means that it is one step lower than the note. # Examples ['G'] -> 5 steps -> ['C'] ['Db'] -> -4 steps -> ['A#'] ['E', 'F'] -> 1 step -> ['F', 'F#']
def transpose(song, interval): sharp="A A# B C C# D D# E F F# G G#".split() flat="A Bb B C Db D Eb E F Gb G Ab".split() return [sharp[((sharp.index(note) if note in sharp else flat.index(note))+12+interval)%12] for note in song]
*You are a composer who just wrote an awesome piece of music. Now it's time to present it to a band that will perform your piece, but there's a problem! The singers vocal range doesn't stretch as your piece requires, and you have to transpose the whole piece.* # Your task Given a list of notes (represented as strings) and an interval, output a list of transposed notes in *sharp* notation. **Input notes may be represented both in flat and sharp notations (more on that below).** **For this kata, assume that input is always valid and the song is *at least* 1 note long.** **Assume that interval is an integer between -12 and 12.** # Short intro to musical notation Transposing a single note means shifting its value by a certain interval. The notes are as following: A, A#, B, C, C#, D, D#, E, F, F#, G, G#. This is using *sharp* notation, where '#' after a note means that it is one step higher than the note. So A# is one step higher than A. An alternative to sharp notation is the *flat* notation: A, Bb, B, C, Db, D, Eb, E, F, Gb, G, Ab. The 'b' after a note means that it is one step lower than the note. # Examples ['G'] -> 5 steps -> ['C'] ['Db'] -> -4 steps -> ['A#'] ['E', 'F'] -> 1 step -> ['F', 'F#']
sharp = ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#'] flat = ['A', 'Bb', 'B', 'C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab'] def transpose(song, interval): return [sharp[((sharp.index(note) if note in sharp else flat.index(note)) + interval) % 12] for note in song]
*You are a composer who just wrote an awesome piece of music. Now it's time to present it to a band that will perform your piece, but there's a problem! The singers vocal range doesn't stretch as your piece requires, and you have to transpose the whole piece.* # Your task Given a list of notes (represented as strings) and an interval, output a list of transposed notes in *sharp* notation. **Input notes may be represented both in flat and sharp notations (more on that below).** **For this kata, assume that input is always valid and the song is *at least* 1 note long.** **Assume that interval is an integer between -12 and 12.** # Short intro to musical notation Transposing a single note means shifting its value by a certain interval. The notes are as following: A, A#, B, C, C#, D, D#, E, F, F#, G, G#. This is using *sharp* notation, where '#' after a note means that it is one step higher than the note. So A# is one step higher than A. An alternative to sharp notation is the *flat* notation: A, Bb, B, C, Db, D, Eb, E, F, Gb, G, Ab. The 'b' after a note means that it is one step lower than the note. # Examples ['G'] -> 5 steps -> ['C'] ['Db'] -> -4 steps -> ['A#'] ['E', 'F'] -> 1 step -> ['F', 'F#']
d = {"Bb": "A#", "Db": "C#", "Eb": "D#", "Gb": "F#", "Ab": "G#"} q = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"] def transpose(a, n): return [q[(q.index(d.get(x, x)) + n) % len(q)] for x in a]
# Write this function ![](http://i.imgur.com/mlbRlEm.png) `for i from 1 to n`, do `i % m` and return the `sum` f(n=10, m=5) // returns 20 (1+2+3+4+0 + 1+2+3+4+0) *You'll need to get a little clever with performance, since n can be a very large number*
def f(n, m): re, c = divmod(n,m) return m*(m-1)/2*re + (c+1)*c/2
# Write this function ![](http://i.imgur.com/mlbRlEm.png) `for i from 1 to n`, do `i % m` and return the `sum` f(n=10, m=5) // returns 20 (1+2+3+4+0 + 1+2+3+4+0) *You'll need to get a little clever with performance, since n can be a very large number*
def f(n, m): # Function to return the sum of the remnainders when n is divided by m for all n from 1 to n # The remainders cycle from 0, 1, 2, 3,... m-1. This happens n // m times, with a final sequnce # up to n % m. The sum of 0, ... m-1 is m * (m - 1) / 2. The sum of 0, 1, 2, 3, n % m is similar. # return (n // m) * (m - 1) * m / 2 + (n % m) * (n % m + 1) / 2
# Write this function ![](http://i.imgur.com/mlbRlEm.png) `for i from 1 to n`, do `i % m` and return the `sum` f(n=10, m=5) // returns 20 (1+2+3+4+0 + 1+2+3+4+0) *You'll need to get a little clever with performance, since n can be a very large number*
def sumrange(n): return (n - 1) * n / 2 def f(n, m): n, m = int(n), int(m) return (n / m) * sumrange(m) + sumrange(n % m + 1)
# Write this function ![](http://i.imgur.com/mlbRlEm.png) `for i from 1 to n`, do `i % m` and return the `sum` f(n=10, m=5) // returns 20 (1+2+3+4+0 + 1+2+3+4+0) *You'll need to get a little clever with performance, since n can be a very large number*
def f(n, m): # Either n or m seems to have a floating-point representation in one of the official tests. # Since it's a .0, converting to int is fine. n, m = int(n), int(m) # n=14, m=5 -> 2 whole runs, plus the 4 first modulos whole_runs = n / m leftovers = n % m # n=5, m=5 -> 1+2+3+4+0 == (m-1)/(m-1+1)/2 per_run = (m - 1) * (m - 1 + 1) / 2 leftovers_sum = leftovers * (leftovers + 1) / 2 return whole_runs * per_run + leftovers_sum
# Write this function ![](http://i.imgur.com/mlbRlEm.png) `for i from 1 to n`, do `i % m` and return the `sum` f(n=10, m=5) // returns 20 (1+2+3+4+0 + 1+2+3+4+0) *You'll need to get a little clever with performance, since n can be a very large number*
def f(n, m): x,y = divmod(n,m) return x * m * (m - 1) / 2 + y * (y + 1) / 2
# Write this function ![](http://i.imgur.com/mlbRlEm.png) `for i from 1 to n`, do `i % m` and return the `sum` f(n=10, m=5) // returns 20 (1+2+3+4+0 + 1+2+3+4+0) *You'll need to get a little clever with performance, since n can be a very large number*
def f(n, m): q, r = divmod(n, m) return q * m * (m - 1) // 2 + r * (r + 1) // 2
# Write this function ![](http://i.imgur.com/mlbRlEm.png) `for i from 1 to n`, do `i % m` and return the `sum` f(n=10, m=5) // returns 20 (1+2+3+4+0 + 1+2+3+4+0) *You'll need to get a little clever with performance, since n can be a very large number*
def f(n, m): k = n // m r = n % m return (m * (m -1) // 2) * k + r * (r + 1) // 2
# Write this function ![](http://i.imgur.com/mlbRlEm.png) `for i from 1 to n`, do `i % m` and return the `sum` f(n=10, m=5) // returns 20 (1+2+3+4+0 + 1+2+3+4+0) *You'll need to get a little clever with performance, since n can be a very large number*
def f(n, m): times = n // m extra = n % m sum_mini_series = (m - 1) * (m - 1 + 1) // 2 sum_extra = (extra) * (extra + 1) // 2 return sum_mini_series * times + sum_extra
# Write this function ![](http://i.imgur.com/mlbRlEm.png) `for i from 1 to n`, do `i % m` and return the `sum` f(n=10, m=5) // returns 20 (1+2+3+4+0 + 1+2+3+4+0) *You'll need to get a little clever with performance, since n can be a very large number*
def f(n, m): sum_1_to_n = lambda n: (n + 1) * n // 2 a, b = divmod(n, m) return a * sum_1_to_n(m - 1) + sum_1_to_n(b)
# Write this function ![](http://i.imgur.com/mlbRlEm.png) `for i from 1 to n`, do `i % m` and return the `sum` f(n=10, m=5) // returns 20 (1+2+3+4+0 + 1+2+3+4+0) *You'll need to get a little clever with performance, since n can be a very large number*
def f(n, m): return ((m-1)**2+(m-1))//2 * (n//m) + ((n%m)**2+(n%m))//2
Write a function that receives two strings as parameter. This strings are in the following format of date: `YYYY/MM/DD`. Your job is: Take the `years` and calculate the difference between them. Examples: ``` '1997/10/10' and '2015/10/10' -> 2015 - 1997 = returns 18 '2015/10/10' and '1997/10/10' -> 2015 - 1997 = returns 18 ``` At this level, you don't need validate months and days to calculate the difference.
def how_many_years (date1,date2): return abs(int(date1.split('/')[0]) - int(date2.split('/')[0]))
Write a function that receives two strings as parameter. This strings are in the following format of date: `YYYY/MM/DD`. Your job is: Take the `years` and calculate the difference between them. Examples: ``` '1997/10/10' and '2015/10/10' -> 2015 - 1997 = returns 18 '2015/10/10' and '1997/10/10' -> 2015 - 1997 = returns 18 ``` At this level, you don't need validate months and days to calculate the difference.
def how_many_years (date1,date2): return abs(int(date1[:4]) - int(date2[:4]))
Write a function that receives two strings as parameter. This strings are in the following format of date: `YYYY/MM/DD`. Your job is: Take the `years` and calculate the difference between them. Examples: ``` '1997/10/10' and '2015/10/10' -> 2015 - 1997 = returns 18 '2015/10/10' and '1997/10/10' -> 2015 - 1997 = returns 18 ``` At this level, you don't need validate months and days to calculate the difference.
def how_many_years (date1,date2): year = lambda d: int(d[:4]) return abs(year(date1) - year(date2))
Write a function that receives two strings as parameter. This strings are in the following format of date: `YYYY/MM/DD`. Your job is: Take the `years` and calculate the difference between them. Examples: ``` '1997/10/10' and '2015/10/10' -> 2015 - 1997 = returns 18 '2015/10/10' and '1997/10/10' -> 2015 - 1997 = returns 18 ``` At this level, you don't need validate months and days to calculate the difference.
def how_many_years (date1, date2): get_year = lambda date: int(date.split('/')[0]) return abs(get_year(date1) - get_year(date2))
Write a function that receives two strings as parameter. This strings are in the following format of date: `YYYY/MM/DD`. Your job is: Take the `years` and calculate the difference between them. Examples: ``` '1997/10/10' and '2015/10/10' -> 2015 - 1997 = returns 18 '2015/10/10' and '1997/10/10' -> 2015 - 1997 = returns 18 ``` At this level, you don't need validate months and days to calculate the difference.
how_many_years = lambda d1,d2: abs(int(''.join(d1[:4])) - int(''.join(d2[:4])))
Write a function that receives two strings as parameter. This strings are in the following format of date: `YYYY/MM/DD`. Your job is: Take the `years` and calculate the difference between them. Examples: ``` '1997/10/10' and '2015/10/10' -> 2015 - 1997 = returns 18 '2015/10/10' and '1997/10/10' -> 2015 - 1997 = returns 18 ``` At this level, you don't need validate months and days to calculate the difference.
def how_many_years (*dates): years = [int(date.split('/')[0]) for date in dates] return abs(years[0]-years[1])
Write a function that receives two strings as parameter. This strings are in the following format of date: `YYYY/MM/DD`. Your job is: Take the `years` and calculate the difference between them. Examples: ``` '1997/10/10' and '2015/10/10' -> 2015 - 1997 = returns 18 '2015/10/10' and '1997/10/10' -> 2015 - 1997 = returns 18 ``` At this level, you don't need validate months and days to calculate the difference.
from datetime import datetime def how_many_years (*dates): d1,d2 = [datetime.strptime(s, "%Y/%m/%d") for s in dates] return abs(d2.year - d1.year)
Write a function that receives two strings as parameter. This strings are in the following format of date: `YYYY/MM/DD`. Your job is: Take the `years` and calculate the difference between them. Examples: ``` '1997/10/10' and '2015/10/10' -> 2015 - 1997 = returns 18 '2015/10/10' and '1997/10/10' -> 2015 - 1997 = returns 18 ``` At this level, you don't need validate months and days to calculate the difference.
HowManyYears = how_many_years = lambda *a: abs(int.__sub__(*(int(d.split('/')[0]) for d in a)))
Write a function that receives two strings as parameter. This strings are in the following format of date: `YYYY/MM/DD`. Your job is: Take the `years` and calculate the difference between them. Examples: ``` '1997/10/10' and '2015/10/10' -> 2015 - 1997 = returns 18 '2015/10/10' and '1997/10/10' -> 2015 - 1997 = returns 18 ``` At this level, you don't need validate months and days to calculate the difference.
def how_many_years (date1,date2): a,b = map(int,map(lambda x: x.split('/')[0],(date1,date2))) return abs(b-a)
Write a function that receives two strings as parameter. This strings are in the following format of date: `YYYY/MM/DD`. Your job is: Take the `years` and calculate the difference between them. Examples: ``` '1997/10/10' and '2015/10/10' -> 2015 - 1997 = returns 18 '2015/10/10' and '1997/10/10' -> 2015 - 1997 = returns 18 ``` At this level, you don't need validate months and days to calculate the difference.
def how_many_years (d1,d2): a=d1[0:4] b=d2[0:4] print( (int(a) , int(b))) return abs(int(a) - int(b))
Now you have to write a function that takes an argument and returns the square of it.
def square(n): return n ** 2
Now you have to write a function that takes an argument and returns the square of it.
def square(n): return n*n
Now you have to write a function that takes an argument and returns the square of it.
square = lambda n: n*n
Now you have to write a function that takes an argument and returns the square of it.
def square(n): return pow(n, 2)
Now you have to write a function that takes an argument and returns the square of it.
def square(n): return n*n if isinstance(n,int) else None
Now you have to write a function that takes an argument and returns the square of it.
def mult(a, b): mv = 0 for c in range(b): mv = sumVal(mv, a) return mv def sumVal(a, b): for c in range(b): a = add1(a) return a def add1(a): out = '' binval = dec2bin(a) carry = 0 convert = True while len(binval) > 0: if not convert: out = binval[-1] + out else: if carry == 1: if binval[-1] == '0': convert = False carry = 0 out = '1' + out else: out = '0' + out else: if binval[-1] == '0': out = '1' + out convert = False else: out = '0' + out carry = 1 binval = binval[:-1] if carry == 1: out = '1' + out return bin2dec(out) def dec2bin(a): if a == 0: return '0' out = '' while a > 0: out = str(a%2) + out a = a //2 return out def bin2dec(a): out = 0 while len(a) > 0: out *= 2 out += int(a[0]) a = a[1:] return out def square(n): return mult(n,n)
Now you have to write a function that takes an argument and returns the square of it.
def square(west_ego): power = 9001 if power > 9000: trump = (power - 1) // len('democracy') freedom = trump kardashian_butt = west_ego illuminati = kardashian_butt * west_ego - freedom + trump if len("illuminati") == len("confirmed!"): return len("ISIS") / 4 * illuminati return 'Putin' > 'Obama'
Now you have to write a function that takes an argument and returns the square of it.
square = lambda n: n**2
Now you have to write a function that takes an argument and returns the square of it.
import math def square(n): return math.pow(float(n), 2)
Now you have to write a function that takes an argument and returns the square of it.
def square(n: int) -> int: """ Get the square of given number `n`. """ return pow(n, 2)
Now you have to write a function that takes an argument and returns the square of it.
square = (2).__rpow__
Now you have to write a function that takes an argument and returns the square of it.
from numpy import square
Now you have to write a function that takes an argument and returns the square of it.
square = lambda i: i ** 2
Now you have to write a function that takes an argument and returns the square of it.
def square(n): return sum(map(lambda x: n, range(0,n)))
Now you have to write a function that takes an argument and returns the square of it.
def square(n): square = n * n return square
Now you have to write a function that takes an argument and returns the square of it.
def square(n): c = n*n return c
Now you have to write a function that takes an argument and returns the square of it.
def square(n): return eval('n'+'+n'*(n-1))
Now you have to write a function that takes an argument and returns the square of it.
def square(n): return n.__mul__(n)
Now you have to write a function that takes an argument and returns the square of it.
def square(n): total=(n*n) return total
Now you have to write a function that takes an argument and returns the square of it.
square = lambda n: n**2 # write a function that takes an argument and returns the square of it
Now you have to write a function that takes an argument and returns the square of it.
def square(n): b = n*n return b
Now you have to write a function that takes an argument and returns the square of it.
def square(n): n **= 2 return n
Now you have to write a function that takes an argument and returns the square of it.
def square(n): c=n**2 return c
Now you have to write a function that takes an argument and returns the square of it.
square = lambda a: a*a
Now you have to write a function that takes an argument and returns the square of it.
def square(n): """ return square of n """ return n*n
Now you have to write a function that takes an argument and returns the square of it.
def square(s): return s**2
Now you have to write a function that takes an argument and returns the square of it.
def square(num): return num **2
Now you have to write a function that takes an argument and returns the square of it.
def square(n): squares = int(n **2) return squares
Now you have to write a function that takes an argument and returns the square of it.
def square(n): return n*n n = 2 print(n)
Now you have to write a function that takes an argument and returns the square of it.
def square(n): return n**2 print((square(2)))
Now you have to write a function that takes an argument and returns the square of it.
def square(n): return n*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*1*n
Now you have to write a function that takes an argument and returns the square of it.
def square(n): return n*n #Completed by Ammar on 12/8/2019 at 11:41PM.
Now you have to write a function that takes an argument and returns the square of it.
def square(n): return n*n#I solved this Kata on 7/19/2019 05:38 AM...#Hussam'sCodingDiary
Now you have to write a function that takes an argument and returns the square of it.
def square(n): return n*n #Simpy return the value of n multiplied by itself
Now you have to write a function that takes an argument and returns the square of it.
def square(n): p = n l = n * p return l
Now you have to write a function that takes an argument and returns the square of it.
import math def square(n): num = n**2 return num
Now you have to write a function that takes an argument and returns the square of it.
def square(n): """Raises n to the power of 2.""" # make it more powerful powerful_n = n ** 2 return powerful_n
Now you have to write a function that takes an argument and returns the square of it.
def square(n): res = 0 for i in range(n): res += n return res
Now you have to write a function that takes an argument and returns the square of it.
def square(n): result ="" if True: result = n**2 return result
Now you have to write a function that takes an argument and returns the square of it.
#Function 2 - squaring an argument def square(n): return n*n
Now you have to write a function that takes an argument and returns the square of it.
def square(n): c = 0 v = 0 while c<n: v += n c += 1 return v
Now you have to write a function that takes an argument and returns the square of it.
def square(n): y = n ** 2 return (y)
Now you have to write a function that takes an argument and returns the square of it.
square=lambda i:i*i
Now you have to write a function that takes an argument and returns the square of it.
square = lambda s:s**2
Now you have to write a function that takes an argument and returns the square of it.
def square(n): return n*n # pass
Now you have to write a function that takes an argument and returns the square of it.
def square(n): m = 0 while m != n*n: m += 1 return m
Now you have to write a function that takes an argument and returns the square of it.
import math def square(n): return int(math.pow(n,2))
Now you have to write a function that takes an argument and returns the square of it.
def square(n): x = int(n)*int(n) return x
Now you have to write a function that takes an argument and returns the square of it.
import math def square(n): n = n**2 return n
Now you have to write a function that takes an argument and returns the square of it.
from scipy.integrate import quad as integrate def square(n): return sum(set([round(value, 5) for value in ( n**2, n*n, (lambda x: x**2)(n), (lambda x: x*x)(n), (lambda x: integrate(lambda a, b: b, min(0,n), max(0,n), args = n))(n)[0], sum(n for _ in range(int(n))) + n*(n - n//1 + 0 if n >= 0 else 1) )]))
Now you have to write a function that takes an argument and returns the square of it.
def square(n): m = n*n return m
Now you have to write a function that takes an argument and returns the square of it.
def square(n): return int(n) * int(n)
Now you have to write a function that takes an argument and returns the square of it.
def square(n): s=n*n return s k=5 square(k) pass
Now you have to write a function that takes an argument and returns the square of it.
square = lambda l : l*l
Now you have to write a function that takes an argument and returns the square of it.
def square(n): product = 1 product = n*n return product
Now you have to write a function that takes an argument and returns the square of it.
def square(n): return sum(n for i in range(n))