1. Converting an Integer into Decimals
import decimal > 10
|
2. Converting an String of Integers into Decimals
import decimal > 12345 |
3. Reversing a String using an Extended Slicing Technique
string = "Python Programming" > gnimmargorP nohtyP |
4. Counting Vowels in a Given Word
vowel = ['a', 'e', 'i', 'o', 'u'] > 3 |
5. Counting Consonants in a Given Word
vowel = ['a', 'e', 'i', 'o', 'u'] > 8 |
6. Counting the Number of Occurances of a Character in a String
word = "python" > 1 |
7. Writing Fibonacci Series
fib = [0,1] # Converting the list of integers to string > 0, 1, 1, 2, 3, 5, 8 |
8. Finding the Maximum Number in a List
numberList = [15, 85, 35, 89, 125] maxNum = numberList[0] > 125 |
9. Finding the Minimum Number in a List
numberList = [15, 85, 35, 89, 125, 2] minNum = numberList[0] > 2 |
10. Finding the Middle Element in a List
numList = [1, 2, 3, 4, 5] print(numList[midElement]) > 3 |
11. Converting a List into a String
lst = ["P", "Y", "T", "H", "O", "N"] print(string) > PYTHON |
12. Adding Two List Elements Together
lst1 = [1, 2, 3] res_lst = [] > [5, 7, 9] |
13. Comparing Two Strings for Anagrams
str1 = "Listen" str1 = list(str1.upper()) if(str1 == str2): > True |
14. Checking for Palindrome Using Extended Slicing Technique
str1 = "Murali".lower() if(str1 == str2[::-1]): |
15. Counting the White Spaces in a String
string = "P r ogramm in g " print(string.count(' ')) > 5 |
16. Counting Digits, Letters, and Spaces in a String
# Importing Regular Expressions Library name = 'Python is 1' digitCount = re.sub("[^0-9]", "", name) print(len(digitCount)) |
17. Counting Special Characters in a String
# Importing Regular Expressions Library count = re.sub('[\w]+', '', spChar) |
18. Removing All Whitespace in a String
import re string = "C O D E" > CODE |
19. Building a Pyramid in Python
floors = 3 > * |
20. Randomizing the Items of a List in Python
lst = ['Python', 'is', 'Easy'] > ['Easy', 'is', 'Python'] |