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

Uncontrolled form input in React-JS

  Uncontrolled form input in React-JS? If we want to take input from users without any separate event handling then we can uncontrolled the data binding technique. The uncontrolled input is similar to the traditional HTML form inputs. The DOM itself handles the form data. Here, the HTML elements maintain their own state that will be updated when the input value changes. To write an uncontrolled component, you need to use a ref to get form values from the DOM. In other words, there is no need to write an event handler for every state update. You can use a ref to access the input field value of the form from the DOM. Example of Uncontrolled Form Input:- import React from "react" ; export class Info extends React . Component {     constructor ( props )     {         super ( props );         this . fun = this . fun . bind ( this ); //event method binding         this . input = React . createRef ();...

JDBC using JSP and Servlet

JDBC means Java Database Connectivity ,It is intermediates from Application to database. JDBC has different type of divers and provides to communicate from database server. JDBC contain four different type of approach to communicate with Database Type 1:- JDBC-ODBC Driver Type2:- JDBC Vendor specific Type3 :- JDBC Network Specific Type4:- JDBC Client-Server based Driver  or JAVA thin driver:- Mostly we prefer Type 4 type of Driver to communicate with database server. Step for JDBC:- 1  Create Database using MYSQL ,ORACLE ,MS-SQL or any other database 2   Create Table using database server 3   Create Form according to database table 4  Submit Form and get form data into servlet 5  write JDBC Code:-     5.1)   import package    import java.sql.*     5.2)  Add JDBC Driver according to database ide tools     5.3)  call driver in program         ...

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...