Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Range
- r = range(5)
- print(r)
- for item in range(5):
- print("Vysakh")
- s = 0
- for item in range(6):
- s += item
- print(s)
- for item in range(2,15,2):
- print(item)
- s = 'aaaaa'
- for item in s:
- print('hi')
- l = [6,3,1,2,9,5]
- x = max(l)
- print(x)
- s = [6,3,1,2,9,5]
- l = min(s)
- print(l)
- ## Counter using digit
- s = 'abcaabcdeefghhhi'
- c = {}
- for item in s:
- if item not in c:
- c[item] = 1
- print(c)
- s = 'abcaabcdeefghhhi'
- c = {}
- for item in s:
- if item not in c:
- c[item] = 1
- else:
- c[item] = c[item] + 1
- print(c)
- ## Listing a directory
- ! ls -l /etc/apache2
- import os
- r = os.listdir('/etc/apache2')
- print(r)
- import os
- for item in os.listdir('/etc'):
- if item.endswith('.conf'):
- print(item)
- ##------------------------------------ Task 2 ------------------------------------------------
- ## 1] dict to list of list
- d = {'sam': 200, 'kevin': 400, 'john': 300 , 'devon':100 }
- l = []
- for item in d:
- k = d[item]
- c = item.split()
- if k not in c:
- c.append(k)
- l.append(c)
- print(l)
- ans] [['sam', 200], ['kevin', 400], ['john', 300], ['devon', 100]]
- ## 2] find the highest ranked employee name.
- ll = [ ["alex",10] , ["sam",8] , ["kevin",5], ["john",3]]
- y = 0
- for item in ll:
- name = item[0]
- rank = item[1]
- if rank > y:
- y = rank
- z = name
- print(z)
- ans] alex
- ## 3] find the sum of odd numbers between 1-100 using range function and forloop
- s = 0
- for item in range(1,101,2):
- s += item
- print(s)
- ans] 2500
- ## 4] - find the occurrence of words.
- s = """The OS includes some common elastic core components, like the GNU tools,
- among others. These kick tools give the user a way to manage the resources
- provided by the kernel, Kernel apple install additional axe knee software, configure performance
- and security Knife settings, and more. eye keep All of odd these tools bundled together
- make up the knee umbrella keen axe functional kick operating system. Because Linux is an open source
- OS, combinations of kick elastic software enrich can vary between Linux distributions."""
- s = s.replace(",","")
- s = s.lower().replace(".","").split()
- y = {}
- for item in s:
- if item not in y:
- y[item] = 0
- if item in y:
- y[item] = y[item] + 1
- print(y)
- ans]
- {'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}
- ## 5 - add the words to dict.
- s = """The OS includes some common elastic core components, like the GNU tools,
- among others. These kick tools give the user a way to manage the resources
- provided by the kernel, Kernel apple install additional axe knee software, configure performance
- and security Knife settings, and more. eye keep All of odd these tools bundled together
- make up the knee umbrella keen axe functional kick operating system. Because Linux is an open source
- OS, combinations of kick elastic software enrich can vary between Linux distributions."""
- s = s.replace(",","")
- s = s.lower().replace(".","").split()
- words = {"a":[] , "e":[] , "i":[] , "o":[] , "u":[]}
- for item in s:
- if item[0] in 'a,e,i,o,u':
- for x in words:
- if x == item[0]:
- words[x].append(item)
- print(words)
- ans]
- {'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']}
- ## 6] list the directory "/etc" find the total number of files ends with ".conf" extension.
- import os
- for item in os.listdir('/etc'):
- if item.endswith('.conf'):
- print(item)
- ans]
- rsyslog.conf
- gai.conf
- xattr.conf
- ld.so.conf
- adduser.conf
- ucf.conf
- fuse.conf
- resolv.conf
- nsswitch.conf
- libaudit.conf
- ca-certificates.conf
- deluser.conf
- nftables.conf
- e2scrub.conf
- host.conf
- sudo_logsrvd.conf
- pam.conf
- sudo.conf
- sysctl.conf
- mke2fs.conf
- debconf.conf
- logrotate.conf
-
Add Comment
Please, Sign In to add comment