
n=10 fib = +fib) for _ in range(n)] print(fib) Output: 11. We use list comprehensions and a for loop to create a Fibonacci series in a single line of code. Fibonacci seriesįibonacci series is a series of numbers in which each number is the sum of two preceding numbers.

Here’s how we can do that: import numpy as np mat =, , ] transpose_matrix = print(np.maxtix(mat)) print(np.matrix(transposeMatrix)) Output: mat: ] transpose_matrix: ] 10. We can transpose a matrix in just one line of code with the help of zip() function and list comprehension. There is an alternative way to print the pattern with a single line of code. n = 5 for i in range(n): for j in range(i+1): print("* ", end="") print("\n") To print a pattern, we often use nested loops and write the logic. We can open a file and read the content of it and assign it to a variable using this one-liner: text = 8. We just need to pass the dictionaries along with (**)operator to a 7. We can merge multiple dictionaries in a single line of code using (**) operator. input_string = "Namaste World!" reversed_string = input_string print("Reversed string is: ", reversed_string) Output: Reversed string is: !dlroW etsamaN 5.

We use string slicing to find the reverse in a single line of code. This code is useful for finding the reverse of a string.

input_list =, ,, , ] output_list = print(output_list) Output: 4. We can flatten a list of lists in a single line of code using list comprehension. sum_of_digit = lambda x: sum(map(int, str(x))) output = sum_of_digit(123) print("Sum of the digits is: ", output) Output: Sum of the digits is: 6 3. This one-liner is useful for finding the sum of digits of a number. But in Python, we can calculate the sum in just a single line of code. To find the sum of digits of a number, we use mathematical operators such as % (modulo) and / division. input_list = list(map(int, input().split())) print(input_list) 2. We can use map() function to convert input() value to an integer value and then add those integer values to the list. While solving coding problems, we often need to take multiple integer inputs in our code. Multiple space-separated inputs in a list
