Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. import operator
  2. #def main():
  3. # 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)
  4.  
  5. def sortByFirst(listOfTuples):
  6. return sorted(listOfTuples,key = lambda x:x[1])
  7. def checkIfIsIn(listOfTuples , firstName):
  8. for tuple in listOfTuples:
  9. if tuple[1] == firstName :
  10. return True
  11. break
  12. return False
  13. operator = {
  14. "+": lambda a, b: a + b,
  15. "*": lambda a, b: a * b,
  16. "/": lambda a, b: a / b,
  17. "%": lambda a, b: a % b
  18. }
  19. def apply_operator(op,a,b):
  20. return operator[op](a,b)
  21. specialOperator = {
  22. "print_all": lambda *a, **k: print(a, k),
  23. "print_args_commas": lambda *a, **k: print(a, k, sep=", "),
  24. "print_only_args": lambda *a, **k: print(a),
  25. "print_only_kwargs": lambda *a, **k: print(k)
  26. }
  27. def unionDictionary(*args):
  28. result = {}
  29. for dict in args:
  30. for elem in dict:
  31. if elem not in result:
  32. result[elem]=[dict[elem]]
  33. else : result[elem].append(dict[elem])
  34. for key,value in result.items() :
  35. if len(value) == 1 :
  36. result[key] = value[0]
  37. return result
  38. #print(unionDictionary({"george":2,"ana":3},{"ana":2,"george":4,"cristi":4}))
  39.  
  40.  
  41.  
  42.  
  43.  
  44. def apply_function(op,*args,**kwargs):
  45. return specialOperator[op](*args,**kwargs)
  46. #apply_function("print_all","george","todirenau",x="george")
  47.  
  48. #dict = {'a': 1,'b':{'c': 3,'d':{'e': 5,'f': 6}}}
  49. #printDictionary(dict,"-")
  50. """
  51. print key
  52. if value = dict
  53. recall
  54. print value
  55. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement