Skip to main content

List Special Operation in Python

We can perform concatenation using + operator, multiplication, or repetition using *  and spiting element of the list using [:] .which has been described by the following example.
a=[1,2,3,7,8,1]
del(a)
b=[4,5,6]
c=a+b
print(c)
c=a*3
print(c)
print(a[1:3])
print(a[1:])
print(a[:3])
print(a[-3:-1])
Assignment of List:-
Check if a key is present in every segment of size k in an array
Find the minimum and maximum element in an array
Write a program to reverse the array
Write a program to sort the given array
Find the Kth largest and Kth smallest number in an array
Find the occurrence of an integer in the array
Sort the array of 0s, 1s, and 2s
Range and Coefficient of array
Move all the negative elements to one side of the array
Find the Union and Intersection of the two sorted arrays
Level 2
Write a program to cyclically rotate an array by one
Find the missing integer
Count Pairs with given sum
Find duplicates in an array
Sort an Array using the Quicksort algorithm
Find common elements in three sorted arrays
Find the first repeating element in an array of integers
Find the first non-repeating element in a given array of integers
Find the largest three elements in an array Time
Rearrange the array in alternating positive and negative items
Find if there is any subarray with sum equal to zero
Find Largest sum contiguous Subarray
Find the factorial of a large number
Find Maximum Product Subarray
Find longest consecutive subsequence
Find the minimum element in a rotated and sorted array
Find all elements that appear more than N/K times
GCD of given index ranges in an array
Minimize the maximum difference between the heights
Minimum number of jumps to reach the end
Find the two repetitive elements in a given array
Find a triplet that sums to a given value
Construct a N*M matrix from the user input
Find the row with the maximum number of 1’s
Print the matrix in a Spiral manner
Find whether an array is a subset of another array
Implement two Stacks in an array
Majority Element
Wave Array
Trapping Rainwater
Level 3
Maximum Index
Max sum path in two arrays
Find Missing And Repeating
Stock buy and sell Problem
Pair with given sum in a sorted array
Chocolate Distribution Problem
Longest Consecutive Subsequence
Print all possible combinations of r elements in a given array

Comments

  1. WAP to count total even number and Odd number in Tuple?
    Sol:-t=(1,2,3,4,5,6,7,8,9)
    count1=0
    count2=0
    for i in t:
    if i%2==0:
    count1=count1+1
    else:
    count2=count2+1
    print("count of even numbers:",count1)
    print("count of odd numbers:",count2)

    ReplyDelete
  2. #Wap to find Negative Elements in list?

    lst=[-2,4,2,-8,5,-4,55,44,-7]
    for i in range(0,len(lst)):
    for j in range(i,len(lst)):
    if lst[i]==lst[i] and lst[i]<0:
    print("Negative Elements",lst[j])
    break

    ReplyDelete
  3. #Wap Program to reverse the list?
    lst=[3,4,2,5,65]
    for i in range(len(lst)-1,-1,-1):
    print(lst[i],end=' ')

    ReplyDelete
  4. #WAP to Find max and min Element in list?
    lst=[44,22,11,55,44]
    maxi=lst[0]
    for i in range(0,len(lst)):
    if maxilst[i]:
    minn=lst[i]
    print("Minimum Element is ",minn)

    ReplyDelete
  5. #WAP to Sort the list using sort() method ?
    lst=[6,4,7,8,2]
    lst.sort()
    print(lst)

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. #Find whether an List is a subset of another List?

    lst=[10,4,5,7,2]
    lst1=[2,7,4]
    for i in lst:
    if i in lst1:
    print("List1 is Subset of List",lst,lst1)
    break

    ReplyDelete
  8. #sorting a ist
    x=[12,25,85,32,14]
    for i in range (0,len(x)):
    for j in range(i+1,len(x)):
    if x[i]>x[j]:
    x[i],x[j]=x[j],x[i]
    print(x)
    #sorting decreasing order:
    x=[12,25,85,32,14]
    for i in range (0,len(x)):
    for j in range(i+1,len(x)):
    if x[i]<x[j]:
    x[i],x[j]=x[j],x[i]
    print(x)

    ReplyDelete
  9. #duplicate element remove
    def Remove(duplicate):
    final_list=[]
    for num in duplicate:
    if num not in final_list:
    final_list.append(num)
    return final_list
    duplicate=[2,4,10,20,5,10,8]
    print(Remove(duplicate))

    #another mathod
    l=[2,4,10,20,5,10,8]
    a=list(set(l))
    print(a)

    ReplyDelete
  10. #find out negative element in the list
    list=[-1,2,5,-3,55,-26,27]
    for i in range (0,len(list)):
    for j in range(i,len(list)):
    if list[i]==list[j]and list[i]<0:
    print("negative element",list[j])
    break

    ReplyDelete
  11. #subset of list
    l1=[1,2,4,5,8]
    l2=[2,5,9,6,4,10,12,25]
    for i in l1:
    if i in l2:
    print("l2 is subset of l1",l1,l2)
    break

    ReplyDelete
  12. #counting even or odd element in tuple
    t=(1,2,3,4,5,7,8,9,)
    count1=0
    count2=0
    for i in t:
    if i%2==0:
    count1=count1+1
    else:
    count2=count2+1
    print("count of even number",count1)
    print("count of even number", count2)

    ReplyDelete
  13. #square of list element
    x = [4, 5, 6, 7, 11, 12]
    y = [i ** 2 for i in x]
    print(y)


    # 2nd method
    def square(list):
    ret = []
    for i in list:
    ret.append(i ** 2)
    return ret
    # 3rd method:
    def square(list):
    for i in list:
    yield i**2

    ReplyDelete

Post a Comment

POST Answer of Questions and ASK to Doubt

Popular posts from this blog

DSA in C# | Data Structure and Algorithm using C#

  DSA in C# |  Data Structure and Algorithm using C#: Lecture 1: Introduction to Data Structures and Algorithms (1 Hour) 1.1 What are Data Structures? Data Structures are ways to store and organize data so it can be used efficiently. Think of data structures as containers that hold data in a specific format. Types of Data Structures: Primitive Data Structures : These are basic structures built into the language. Example: int , float , char , bool in C#. Example : csharp int age = 25;  // 'age' stores an integer value. bool isStudent = true;  // 'isStudent' stores a boolean value. Non-Primitive Data Structures : These are more complex and are built using primitive types. They are divided into: Linear : Arrays, Lists, Queues, Stacks (data is arranged in a sequence). Non-Linear : Trees, Graphs (data is connected in more complex ways). Example : // Array is a simple linear data structure int[] number...

Conditional Statement in Python

It is used to solve condition-based problems using if and else block-level statement. it provides a separate block for  if statement, else statement, and elif statement . elif statement is similar to elseif statement of C, C++ and Java languages. Type of Conditional Statement:- 1) Simple if:- We can write a single if statement also in python, it will execute when the condition is true. for example, One real-world problem is here?? we want to display the salary of employees when the salary will be above 10000 otherwise not displayed. Syntax:- if(condition):    statements The solution to the above problem sal = int(input("Enter salary")) if sal>10000:     print("Salary is "+str(sal)) Q)  WAP to increase the salary of employees from 500 if entered salary will be less than 10000 otherwise the same salaries will be displayed. Solution:- x = int(input("enter salary")) if x<10000:     x=x+500 print(x)   Q) WAP to display th...

JSP Page design using Internal CSS

  JSP is used to design the user interface of an application, CSS is used to provide set of properties. Jsp provide proper page template to create user interface of dynamic web application. We can write CSS using three different ways 1)  inline CSS:-   we will write CSS tag under HTML elements <div style="width:200px; height:100px; background-color:green;"></div> 2)  Internal CSS:-  we will write CSS under <style> block. <style type="text/css"> #abc { width:200px;  height:100px;  background-color:green; } </style> <div id="abc"></div> 3) External CSS:-  we will write CSS to create a separate file and link it into HTML Web pages. create a separate file and named it style.css #abc { width:200px;  height:100px;  background-color:green; } go into Jsp page and link style.css <link href="style.css"  type="text/css" rel="stylesheet"   /> <div id="abc"> </div> Exam...