0% found this document useful (0 votes)
12 views4 pages

Python Programming

Uploaded by

majianupam437
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Python Programming

Uploaded by

majianupam437
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1. Create a list of 10 numbers and print the even numbers.

2. Find the maximum and minimum element in a list.


3. Count the number of occurrences of a given element in a list.
4. Remove all duplicates from a list.
5. Reverse a list without using the reverse() method.
6. Check if a list is a palindrome (same forward and backward).
7. Insert an element at the 3rd position in a list.
8. Swap the first and last element of a list.
9. Check if all elements in the list are unique.
10. Sum all numbers in a list using a loop.
11. Sort a list of strings by their length.
12. Flatten a nested list (e.g., [[1,2],[3,4]] → [1,2,3,4]).
13. Find common elements in two lists.
14. Rotate a list to the right by k positions.
15. Split a list into chunks of size n.
16. Write a list comprehension to square only even numbers.
17. Filter out all elements less than a certain number.
18. Create a list of tuples from two lists (like a zip).
19. Merge two sorted lists into one sorted list (without using sort).
20. Count how many elements are greater than the average of the list.
21. Transpose a matrix using list comprehension.
22. Write your own map() function using a list and a function.
23. Detect and remove all elements that appear more than once.
24. Convert a list of strings to a single string (with delimiter).
25. Find all pairs in a list whose sum is equal to a given number.
26. Create a frequency dictionary from a list.
27. Group elements of a list by their data type.
28. Use list comprehension to generate a multiplication table.
29. Find the second largest element in the list.
30. Implement a matrix multiplication using nested list comprehensions.
31. Create a tuple of 5 numbers and print each element.
32. Access the last element of a tuple.
33. Check if a given element exists in a tuple.
34. Find the length of a tuple.
35. Convert a tuple to a list and back to a tuple.
36. Concatenate two tuples.
37. Repeat a tuple 3 times.
38. Count the number of times a value appears in a tuple.
39. Find the index of a particular value in a tuple.
40. Check if all elements in a tuple are numbers.
41. Unpack a tuple into individual variables.
42. Create a tuple of squares of numbers from 1 to 10.
43. Create a nested tuple and access elements from it.
44. Write a program to remove duplicates from a tuple.
45. Sort a tuple of numbers in ascending order (convert to list and
back).
46. Find the maximum and minimum elements in a tuple.
47. Convert a string into a tuple of characters.
48. Zip two lists into a tuple list.
49. Find the sum of all elements in a tuple.
50. Write a function that takes a tuple and returns a reversed tuple.
51. Flatten a nested tuple (e.g., ((1,2), (3,4)) → (1,2,3,4)).
52. Create a tuple of tuples where each inner tuple contains a number
and its square.
53. Write a function that returns the frequency count of each element
in a tuple.
54. Use a tuple to represent coordinates and calculate the distance
between two points.
55. Check if two tuples have any elements in common.
56. Group elements of a list into a tuple of fixed size (e.g., group of
3).
57. Create a tuple containing mixed data types and print their types.
58. Use list comprehension to generate a tuple of even numbers from 1
to 50.
59. Check if a tuple is a palindrome.
60. Merge two dictionaries.
61. Find Keys with Maximum Value in a Dictionary.
62. Count Frequency of Characters using dictionary.
63. Find the Longest Consecutive Sequence in an Unsorted Array
64. Write a Python program to input a string and display it.
65. Write a Python program to find the length of a string without using
len().
66. Write a program to copy one string into another.
67. Write a Python program to compare two strings and check if they are
equal.
68. Write a program to concatenate two strings without using +.
69. Write a Python program to convert a string to uppercase and
lowercase.
70. Write a program to count the number of vowels and consonants in a
string.
71. Write a Python program to count the number of words in a sentence.
72. Write a program to find the first and last character of a string.
73. Write a program to print each character of a string on a new line.
74. Write a Python program to reverse a string without using built-in
functions.
75. Write a program to check whether a string is a palindrome.
76. Write a Python program to find the frequency of each character in a
string.
77. Write a program to remove all vowels from a string.
78. Write a Python program to remove all duplicate characters from a
string.
79. Write a program to count the number of digits, letters, and special
characters in a string.
80. Write a Python program to toggle the case of each character in a
string.
81. Write a program to check whether two strings are anagrams.
82. Write a program to sort the characters of a string alphabetically.
83. Write a program to find the longest word in a sentence.
84. Write a Python program to implement your own version of strstr()
(substring search).
85. Write a program to find the longest palindrome substring in a given
string.
86. Write a Python program to encode a string using Run Length Encoding
(RLE).
87. Write a function that checks whether a string is a valid number
(like int() or float()).
88. Write a program to implement simple wildcard pattern matching with
* and ?.
89. Write a Python program to print all permutations of a string using
recursion.
90. Write a function to implement a custom string tokenizer (strtok
behavior).
91. Write a Python function to match strings with regex-like patterns
(. and *).
92. Write a program to find the first non-repeating character in a
string.
93. Generate a random float between 0 and 1.
94. Generate a random integer between 10 and 50 (inclusive).
95. Randomly select an item from a list of strings.
96. Shuffle a list of integers randomly.
97. Generate a random number from a range with step size (e.g., even
numbers between 10 and 50).
98. Pick a random character from a string.
99. Create a list of 5 random integers between 1 and 100.
100. Write a function to simulate rolling two six-sided dice and
returning the sum.
101. Set a seed and generate a predictable sequence of random numbers.
102. Select 5 unique random numbers from a range of 1 to 20.
103. Simulate a lottery draw: pick 6 unique numbers from 1 to 49.
104. Write a function to return a list of n random elements from a given
list.
105. Compare randint() and randrange() by generating numbers using both.
106. Generate a random float between two given numbers.
107. Write a function to add two numbers.
108. Write a function to check if a number is even or odd.
109. Write a function to return the maximum of three numbers.
110. Write a function to compute the factorial of a number.
111. Write a function to check if a string is a palindrome.
112. Write a function to reverse a string.
113. Write a function to calculate the square and cube of a number.
114. Write a function to convert Celsius to Fahrenheit.
115. Write a function to check if a number is positive, negative, or
zero.
116. Write a function to sum all elements in a list.
117. Write a function to generate the nth Fibonacci number.
118. Write a function to check if a number is prime.
119. Write a function to count the vowels in a string.
120. Write a function to remove duplicates from a list.
121. Write a function to find the second largest number in a list.
122. Write a function to sort a list without using built-in sort().
123. Write a function to check if a list is a palindrome.
124. Write a function to find the GCD and LCM of two numbers.
125. Write a function to find the longest word in a list.
126. Write a function to return the number of words in a sentence.
127. Write a function to implement a Caesar Cipher.
128. Write a function to check if parentheses are balanced in an
expression.
129. Write a function to find all anagrams of a word from a list.
130. Write a function to validate a Sudoku board.
131. Write a function to merge two sorted lists without using sorted().
132. Write a function to generate all permutations of a string.
133. Write a function to group words that are anagrams of each other.
134. Write a function to find the longest increasing subsequence in a
list.
135. Write a function to simulate a basic calculator supporting +, -, *,
/.
136. Write a function to parse and evaluate a simple math expression
from a string (e.g., "2 + 3 * 4").
137. Write a function that simulates a weighted coin toss (e.g., 70%
heads, 30% tails).
138. Generate a random password of a given length including letters,
digits, and symbols.
139. Generate a random date between two datetime objects.
140. Implement a random walk in 2D space for n steps and return final
coordinates.
141. Simulate a deck of cards and draw 5 random cards without
replacement.
142. Create a Markov chain-like random text generator based on word
transitions.
143. Simulate a dice game where the outcome depends on custom weights
for each face.

You might also like