Write a Python Program to Sort The List According to The Second Element in Sublist

preview_player
Показать описание
Hello Programmers, Welcome to my channel.

In this video you will learn about how to Write a Python Program to Sort The List According to The Second Element in Sublist

Python Scripts
======================

Python Functions Solved
==========================

Python Programs Solved
============================

Code 1
=============================
def return_second_item(mysublist):
return mysublist[1]

my_list = [[4, 5, 50], [1, 2, 3, 100], [6, 90], [7, 8, 9, 10]]

new_list = sorted(my_list, key=return_second_item)
print(new_list)

OUTPUT
======================================
[[1, 2, 3, 100], [4, 5, 50], [7, 8, 9, 10], [6, 90]]

Code 2
===================================
def return_second_item(sublist):
return sublist[1]

my_list = [[4, 50, 50], [1, 2000, 3, 100], [6, 90], [7, 8, 9, 10]]

new_list = sorted(my_list, key=return_second_item)
print(new_list)

OUTPUT
==================
[[7, 8, 9, 10], [4, 50, 50], [6, 90], [1, 2000, 3, 100]]

Keywords
=============================
#python #python3 #python_assignment #pythonprogramming #pythontutorial #pythonprojects #pythoncourse #pythonbaba #pythonforbeginners #pythonautomation #pythonbasic #pythonbeginners