What is the following function return item from the list with Min value?

Python List min() Method


Advertisements

Previous Page
Next Page

sort() method

The sort() method is a built-in Python method that, by default, sorts the list in ascending order. However, you can modify the order from ascending to descending by specifying the sorting criteria.

Example

Let's say you want to sort the element in prices in ascending order. You would type prices followed by a . (period) followed by the method name, i.e., sort including the parentheses.

prices = [238.11, 237.81, 238.91] prices.sort() print(prices) [237.81, 238.11, 238.91]

type() function

For the type() function, it returns the class type of an object.

Example

Here we will see what type of both fam and fam2 are:

fam = ["liz", 1.73, "emma", 1.68, "mom", 1.71, "dad", 1.89] fam ['liz', 1.73, 'emma', 1.68, 'mom', 1.71, 'dad', 1.89]

Let's see what the type of the object is:

type(fam) list

Now, let's look at fam2.

fam2 = [["liz", 1.73], ["emma", 1.68], ["mom", 1.71], ["dad", 1.89]] fam2 [['liz', 1.73], ['emma', 1.68], ['mom', 1.71], ['dad', 1.89]]

Let's see what the type of the object is:

type(fam2) list

These calls show that both fam and fam2 are in fact lists.

append() method

The append() method will add certain content you enter to the end of the elements you select.

Example

In this example, let’s extend the string by adding “April” to the list with the method append(). Using append() will increase the length of the list by 1.

months = ['January', 'February', 'March'] months.append('April') print(months)

When you run the above code, it produces the following result:

['January', 'February', 'March', 'April']

Python min()

In this tutorial, we will learn about the Python min() function with the help of examples.

The min() function returns the smallest item in an iterable. It can also be used to find the smallest item between two or more parameters.

Example

numbers = [9, 34, 11, -4, 27]
# find the smallest number min_number = min(numbers)
print(min_number) # Output: -4

The min() function has two forms:

# to find the smallest item in an iterable min(iterable, *iterables, key, default) # to find the smallest item between two or more objects min(arg1, arg2, *args, key)

Python | Maximum and minimum element’s position in a list

Given a list of N integers, find the maximum and minimum element’s position in the list.

Examples:

Input : 3, 4, 1, 3, 4, 5 Output : The maximum is at position 6 The minimum is at position 3

List Methods in Python | Set 1 (in, not in, len(), min(), max()…)

List basics have been covered in python in the set below
Data Types-List, Tuples and Iterations

List methods are discussed in this articles.
1. “in” operator :- This operator is used to check if an element is present in the list or not. Returns true if element is present in list else returns false.
2. “not in” operator :- This operator is used to check if an element is not present in the list or not. Returns true if element is not present in list else returns false.




# Python code to demonstrate the working of
# "in" and "not in"
# initializing list
lis = [1, 4, 3, 2, 5]
# checking if 4 is in list using "in"
if 4 in lis:
print ("List is having element with value 4")
else : print ("List is not having element with value 4")
# checking if 4 is not list using "not in"
if 4 not in lis:
print ("List is not having element with value 4")
else : print ("List is having element with value 4")

Output:

List is having element with value 4 List is having element with value 4

3. len() :- This function returns the length of list.
4. min() :- This function returns the minimum element of list.
5. max() :- This function returns the maximum element of list.




# Python code to demonstrate the working of
# len(), min() and max()
# initializing list 1
lis = [2, 1, 3, 5, 4]
# using len() to print length of list
print ("The length of list is : ", end="")
print (len(lis))
# using min() to print minimum element of list
print ("The minimum element of list is : ", end="")
print (min(lis))
# using max() to print maximum element of list
print ("The maximum element of list is : ", end="")
print (max(lis))

Output:



The length of list is : 5 The minimum element of list is : 1 The maximum element of list is : 5

6. “+” operator :- This operator is used to concatenate two lists into a single list.
7. “*” operator :- This operator is used to multiply the list “n” times and return the single list.




# Python code to demonstrate the working of
# "+" and "*"
# initializing list 1
lis = [1, 2, 3]
# initializing list 2
lis1 = [4, 5, 6]
# using "+" to concatenate lists
lis2= lis + lis1
# printing concatenated lists
print ("list after concatenation is : ", end="")
for i in range(0,len(lis2)):
print (lis2[i], end=" ")
print ("\r")
#using '*' to combine lists
lis3 = lis * 3
# printing combined lists
print ("list after combining is : ", end="")
for i in range(0,len(lis3)):
print (lis3[i], end=" ")

Output:

list after concatenation is : 1 2 3 4 5 6 list after combining is : 1 2 3 1 2 3 1 2 3

8. index(ele, beg, end) :- This function returns the index of first occurrence of element after beg and before end.
9. count() :- This function counts the number of occurrences of elements in list.




# Python code to demonstrate the working of
# index() and count()
# initializing list 1
lis = [2, 1, 3, 5, 4, 3]
# using index() to print first occurrence of 3
# prints 5
print ("The first occurrence of 3 after 3rd position is : ", end="")
print (lis.index(3, 3, 6))
# using count() to count number of occurrence of 3
print ("The number of occurrences of 3 is : ", end="")
print (lis.count(3))

Output:

The first occurrence of 3 after 3rd position is : 5 The number of occurrences of 3 is : 2

Related articles:
List methods in Python
List Methods in Python | Set 2 (del, remove(), sort(), insert(), pop(), extend()…)

This article is contributed by Manjeet Singh .If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course




Article Tags :
Python
School Programming
python-list
python-list-functions
Practice Tags :
python-list