map.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. def f(x):
  2. return x**2
  3. def test_f():
  4. a = [1, 2, -3, 4, -2]
  5. b = list(map(abs, a))
  6. b = list(map(f, a))
  7. st = ['qwerty', 'qwer', 'asdfg']
  8. st_1 = list(map(str.upper, st))
  9. st_2 = list(map(lambda x: x[::-1], st))
  10. st_3 = list(map(lambda x: x + '!!!', st))
  11. st_4 = list(map(list, st))
  12. st_5 = list(map(sorted, st_4))
  13. print(st)
  14. print(st_1)
  15. print(st_2)
  16. print(st_3)
  17. print(st_4)
  18. print(st_5)
  19. print(b)
  20. # test_f()
  21. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  22. def numbers_to_string():
  23. numbers = [116, -411, 448, 636, -254, -295, 220, 216, 187, -150, -458, -372, 450, 141, -626, -168, -383, 389, -184, 609, 221, 311, 526, 254, -631, -174, -555, -338, 226, 695, -16, 333, 12, -600, -258, -383, -101, 121, 40, 278, 118, -462, -671, 78, -69, -568, -228, -445, -47, -565]
  24. strings = list(map(str, numbers))
  25. print(strings)
  26. # numbers_to_string()
  27. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  28. def increase():
  29. numbers = [116, -411, 448, 636, -254, -295, 220, 216, 187, -150, -458, -372, 450, 141, -626, -168, -383, 389, -184, 609, 221, 311, 526, 254, -631, -174, -555, -338, 226, 695, -16, 333, 12, -600, -258, -383, -101, 121, 40, 278, 118, -462, -671, 78, -69, -568, -228, -445, -47, -565]
  30. increase_3 = list(map(lambda x: x*3, numbers))
  31. print(increase_3)
  32. # increase()
  33. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  34. def to_sqr():
  35. numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  36. print(list(map(lambda x: x**2, numbers)))
  37. print(list(map(lambda x: x**3, numbers)))
  38. # to_sqr()
  39. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  40. # 0123456
  41. #RRGGBB
  42. def from_hex_to_rgb(color: str) -> tuple:
  43. return (int(color[1:3], 16), int(color[3:5], 16), int(color[5:], 16))
  44. colors = ['#B22222', '#DC143C', '#FF0000', '#FF6347', '#FF7F50', '#CD5C5C', '#F08080', '#E9967A',
  45. '#FA8072', '#FFA07A', '#FF4500', '#FF8C00', '#FFA500', '#FFD700', '#B8860B', '#DAA520',
  46. '#EEE8AA', '#BDB76B', '#F0E68C', '#808000', '#FFFF00', '#9ACD32', '#556B2F', '#6B8E23',
  47. '#7CFC00', '#7FFF00', '#ADFF2F']
  48. # for red, green, blue in map(from_hex_to_rgb, colors):
  49. # print(f"Red={red}, Green={green}, Blue={blue}")
  50. # print(from_hex_to_rgb('#87CEFA'))
  51. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  52. # my_list = list(input().split())
  53. def to_str():
  54. test_list = ['q', 'w', 'e', 'r', 't', 'y']
  55. new_list = list(map(lambda x: (x.upper(), x.lower()), test_list))
  56. print(new_list)
  57. # to_str()
  58. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  59. names = [('Gerald', 'Tucker'), ('Tricia', 'Johnson'), ('Robert', 'Mendez'),
  60. ('Shawn', 'Gutierrez'), ('Gary', 'Ross'), ('Melanie', 'Warren'),
  61. ('Drew', 'May'), ('Jennifer', 'Carroll'), ('Ann', 'Lynn'), ('Ralph', 'Vazquez'),
  62. ('Brittany', 'Erickson'), ('Mark', 'Montoya'), ('Randall', 'Hicks'),
  63. ('Tyler', 'Miller'), ('Bryan', 'Brown'), ('Joshua', 'Sawyer'),
  64. ('Sarah', 'Phillips'), ('Donna', 'Davenport'), ('Rebekah', 'Johnson'),
  65. ('Andrew', 'Reynolds'), ('April', 'Turner'), ('Amanda', 'Ryan'), ('Jennifer', 'Poole'),
  66. ('Jonathan', 'Lane'), ('Laura', 'Stone'), ('Sara', 'Brown'), ('Alexander', 'Johnson'),
  67. ('Emily', 'Phillips'), ('Tyler', 'Smith'), ('Victor', 'Kelly'), ('Audrey', 'Thomas'),
  68. ('Melissa', 'Green'), ('Bethany', 'Holt'), ('Christopher', 'Kerr'), ('Gabrielle', 'Black'),
  69. ('Jennifer', 'Wade'), ('Douglas', 'Horton'), ('Steven', 'Welch'),
  70. ('Terri', 'Thompson'), ('Cassandra', 'Nelson'), ('Andrew', 'Jones'),
  71. ('James', 'Schultz'), ('Richard', 'Castillo'), ('Shaun', 'Logan'),
  72. ('Danielle', 'Lane'), ('Mark', 'Anderson'), ('Charles', 'Shaw'),
  73. ('Derrick', 'Grant'), ('Tracy', 'Pierce'), ('Robert', 'Washington')]
  74. # print(list(map(lambda x: x[0] + ' ' + x[1], names)))
  75. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  76. persons = [
  77. {
  78. 'birthday': '1983-10-25',
  79. 'job': 'Field seismologist',
  80. 'name': 'Andrew Hernandez',
  81. 'phone': '680-436-8521x3468'
  82. },
  83. {
  84. 'birthday': '1993-10-03',
  85. 'job': 'Pathologist',
  86. 'name': 'Paul Harmon',
  87. 'phone': '602.518.4130'
  88. },
  89. {
  90. 'birthday': '2002-06-11',
  91. 'job': 'Designer, multimedia',
  92. 'name': 'Gregory Flores',
  93. 'phone': '691-498-5303x079'
  94. },
  95. {
  96. 'birthday': '2006-11-28',
  97. 'job': 'Print production planner',
  98. 'name': 'Jodi Garcia',
  99. 'phone': '(471)195-7189'},
  100. {
  101. 'birthday': '2019-12-05',
  102. 'job': 'Warehouse manager',
  103. 'name': 'Elizabeth Cannon',
  104. 'phone': '001-098-434-5950x276'
  105. },
  106. {
  107. 'birthday': '1984-06-12',
  108. 'job': 'Visual merchandiser',
  109. 'name': 'Troy Lucas',
  110. 'phone': '+1-018-070-2288x18433'
  111. },
  112. {
  113. 'birthday': '1993-09-14',
  114. 'job': 'International aid/development worker',
  115. 'name': 'Laurie Sandoval',
  116. 'phone': '2930693269'
  117. },
  118. {
  119. 'birthday': '1999-05-25',
  120. 'job': 'Editor, film/video',
  121. 'name': 'Jack Clark',
  122. 'phone': '8643048473'
  123. },
  124. {
  125. 'birthday': '1985-09-11',
  126. 'job': 'Magazine journalist',
  127. 'name': 'Kimberly Johnson',
  128. 'phone': '+1-583-428-7663'
  129. },
  130. {
  131. 'birthday': '1990-10-07',
  132. 'job': 'Museum/gallery curator',
  133. 'name': 'Austin Liu PhD',
  134. 'phone': '714-879-5250'
  135. }
  136. ]
  137. # phones = list(map(lambda x: x['phone'], persons))
  138. # print(phones)
  139. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  140. list_x = [25, 48, 23, 13, -18, -10, -3, 16, 2, -12, 20, -14, 14, 45, 41, 6, 11, 15, 22,
  141. -14, -11, 41, 15, 48, 47, 41, -8, 1, 4, 1, 40, 27, -11, -2, -14, -15, 35, 4,
  142. 49, 4, 5, 13, 50, 35, -3, 3, 30, -11, 7, 12]
  143. list_y = [-9, 17, 41, 47, -5, -10, -5, 13, 31, -11, 37, 9, 46, 27, -1, 36, 32, 23, -12,
  144. 38, 8, 9, 17, 16, 29, -4, 4, 2, 1, 46, 6, 49, -16, 21, -19, -10, 15, -13, 20,
  145. 13, -18, 21, -17, 21, 10, 5, 38, -1, 18, 22]
  146. list_w = [9, -26, 3, 21, 48, -14, 43, -4, -16, 16, 41, 43, -27, -9, 10, -10, 4, -2, 1,
  147. 7, 30, -29, 11, 17, 31, 31, -26, 38, 38, -17, 35, 17, 35, 10, -25, 42, -30,
  148. -10, -20, 20, 15, 0, 29, -30, -21, -13, -27, -21, -18, -26]
  149. print(list(map(lambda x, y, w: x**2-x*y*w+w**4, list_x, list_y, list_w)))