Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import operator
- #def main():
- # finalLines = sorted([word.rsplit('-')for word in open("sample.txt").read().split('\n') if len(word.rsplit('-'))==5],key = lambda x: x[1],reverse=False)
- def sortByFirst(listOfTuples):
- return sorted(listOfTuples,key = lambda x:x[1])
- def checkIfIsIn(listOfTuples , firstName):
- for tuple in listOfTuples:
- if tuple[1] == firstName :
- return True
- break
- return False
- operator = {
- "+": lambda a, b: a + b,
- "*": lambda a, b: a * b,
- "/": lambda a, b: a / b,
- "%": lambda a, b: a % b
- }
- def apply_operator(op,a,b):
- return operator[op](a,b)
- specialOperator = {
- "print_all": lambda *a, **k: print(a, k),
- "print_args_commas": lambda *a, **k: print(a, k, sep=", "),
- "print_only_args": lambda *a, **k: print(a),
- "print_only_kwargs": lambda *a, **k: print(k)
- }
- def unionDictionary(*args):
- result = {}
- for dict in args:
- for elem in dict:
- if elem not in result:
- result[elem]=[dict[elem]]
- else : result[elem].append(dict[elem])
- for key,value in result.items() :
- if len(value) == 1 :
- result[key] = value[0]
- return result
- #print(unionDictionary({"george":2,"ana":3},{"ana":2,"george":4,"cristi":4}))
- def apply_function(op,*args,**kwargs):
- return specialOperator[op](*args,**kwargs)
- #apply_function("print_all","george","todirenau",x="george")
- #dict = {'a': 1,'b':{'c': 3,'d':{'e': 5,'f': 6}}}
- #printDictionary(dict,"-")
- """
- print key
- if value = dict
- recall
- print value
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement