chrisluiz16

Untitled

Jul 22nd, 2023
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. ## Range
  2.  
  3. r = range(5)
  4. print(r)
  5.  
  6. for item in range(5):
  7. print("Vysakh")
  8.  
  9. s = 0
  10. for item in range(6):
  11. s += item
  12. print(s)
  13.  
  14. for item in range(2,15,2):
  15. print(item)
  16.  
  17. s = 'aaaaa'
  18. for item in s:
  19. print('hi')
  20.  
  21. l = [6,3,1,2,9,5]
  22. x = max(l)
  23. print(x)
  24.  
  25. s = [6,3,1,2,9,5]
  26. l = min(s)
  27. print(l)
  28.  
  29. ## Counter using digit
  30.  
  31. s = 'abcaabcdeefghhhi'
  32. c = {}
  33. for item in s:
  34. if item not in c:
  35. c[item] = 1
  36. print(c)
  37.  
  38. s = 'abcaabcdeefghhhi'
  39. c = {}
  40. for item in s:
  41. if item not in c:
  42. c[item] = 1
  43. else:
  44. c[item] = c[item] + 1
  45. print(c)
  46.  
  47. ## Listing a directory
  48.  
  49. ! ls -l /etc/apache2
  50.  
  51. import os
  52. r = os.listdir('/etc/apache2')
  53. print(r)
  54.  
  55. import os
  56. for item in os.listdir('/etc'):
  57. if item.endswith('.conf'):
  58. print(item)
  59.  
  60. ##------------------------------------ Task 2 ------------------------------------------------
  61.  
  62. ## 1] dict to list of list
  63.  
  64. d = {'sam': 200, 'kevin': 400, 'john': 300 , 'devon':100 }
  65. l = []
  66.  
  67. for item in d:
  68. k = d[item]
  69. c = item.split()
  70. if k not in c:
  71. c.append(k)
  72. l.append(c)
  73. print(l)
  74.  
  75. ans] [['sam', 200], ['kevin', 400], ['john', 300], ['devon', 100]]
  76.  
  77.  
  78. ## 2] find the highest ranked employee name.
  79.  
  80. ll = [ ["alex",10] , ["sam",8] , ["kevin",5], ["john",3]]
  81. y = 0
  82.  
  83. for item in ll:
  84. name = item[0]
  85. rank = item[1]
  86. if rank > y:
  87. y = rank
  88. z = name
  89. print(z)
  90.  
  91. ans] alex
  92.  
  93. ## 3] find the sum of odd numbers between 1-100 using range function and forloop
  94.  
  95. s = 0
  96. for item in range(1,101,2):
  97. s += item
  98. print(s)
  99.  
  100. ans] 2500
  101.  
  102. ## 4] - find the occurrence of words.
  103.  
  104. s = """The OS includes some common elastic core components, like the GNU tools,
  105. among others. These kick tools give the user a way to manage the resources
  106. provided by the kernel, Kernel apple install additional axe knee software, configure performance
  107. and security Knife settings, and more. eye keep All of odd these tools bundled together
  108. make up the knee umbrella keen axe functional kick operating system. Because Linux is an open source
  109. OS, combinations of kick elastic software enrich can vary between Linux distributions."""
  110.  
  111. s = s.replace(",","")
  112. s = s.lower().replace(".","").split()
  113. y = {}
  114. for item in s:
  115. if item not in y:
  116. y[item] = 0
  117. if item in y:
  118. y[item] = y[item] + 1
  119. print(y)
  120.  
  121. ans]
  122. {'the': 6, 'os': 2, 'includes': 1, 'some': 1, 'common': 1, 'elastic': 2, 'core': 1, 'components': 1, 'like': 1, 'gnu': 1, 'tools': 3, 'among': 1, 'others': 1, 'these': 2, 'kick': 3, 'give': 1, 'user': 1, 'a': 1, 'way': 1, 'to': 1, 'manage': 1, 'resources': 1, 'provided': 1, 'by': 1, 'kernel': 2, 'apple': 1, 'install': 1, 'additional': 1, 'axe': 2, 'knee': 2, 'software': 2, 'configure': 1, 'performance': 1, 'and': 2, 'security': 1, 'knife': 1, 'settings': 1, 'more': 1, 'eye': 1, 'keep': 1, 'all': 1, 'of': 2, 'odd': 1, 'bundled': 1, 'together': 1, 'make': 1, 'up': 1, 'umbrella': 1, 'keen': 1, 'functional': 1, 'operating': 1, 'system': 1, 'because': 1, 'linux': 2, 'is': 1, 'an': 1, 'open': 1, 'source': 1, 'combinations': 1, 'enrich': 1, 'can': 1, 'vary': 1, 'between': 1, 'distributions': 1}
  123.  
  124.  
  125. ## 5 - add the words to dict.
  126.  
  127.  
  128. s = """The OS includes some common elastic core components, like the GNU tools,
  129. among others. These kick tools give the user a way to manage the resources
  130. provided by the kernel, Kernel apple install additional axe knee software, configure performance
  131. and security Knife settings, and more. eye keep All of odd these tools bundled together
  132. make up the knee umbrella keen axe functional kick operating system. Because Linux is an open source
  133. OS, combinations of kick elastic software enrich can vary between Linux distributions."""
  134.  
  135. s = s.replace(",","")
  136. s = s.lower().replace(".","").split()
  137. words = {"a":[] , "e":[] , "i":[] , "o":[] , "u":[]}
  138.  
  139. for item in s:
  140. if item[0] in 'a,e,i,o,u':
  141. for x in words:
  142. if x == item[0]:
  143. words[x].append(item)
  144. print(words)
  145.  
  146. ans]
  147. {'a': ['among', 'a', 'apple', 'additional', 'axe', 'and', 'and', 'all', 'axe', 'an'], 'e': ['elastic', 'eye', 'elastic', 'enrich'], 'i': ['includes', 'install', 'is'], 'o': ['os', 'others', 'of', 'odd', 'operating', 'open', 'os', 'of'], 'u': ['user', 'up', 'umbrella']}
  148.  
  149.  
  150. ## 6] list the directory "/etc" find the total number of files ends with ".conf" extension.
  151.  
  152. import os
  153. for item in os.listdir('/etc'):
  154. if item.endswith('.conf'):
  155. print(item)
  156.  
  157. ans]
  158. rsyslog.conf
  159. gai.conf
  160. xattr.conf
  161. ld.so.conf
  162. adduser.conf
  163. ucf.conf
  164. fuse.conf
  165. resolv.conf
  166. nsswitch.conf
  167. libaudit.conf
  168. ca-certificates.conf
  169. deluser.conf
  170. nftables.conf
  171. e2scrub.conf
  172. host.conf
  173. sudo_logsrvd.conf
  174. pam.conf
  175. sudo.conf
  176. sysctl.conf
  177. mke2fs.conf
  178. debconf.conf
  179. logrotate.conf
  180. ​
  181.  
  182.  
Add Comment
Please, Sign In to add comment