0% found this document useful (0 votes)
11 views2 pages

Assigmment 1

The document contains two Python programming assignments. The first program separates even and odd elements from a list into two new lists. The second program sorts a list of strings by the length of each string.

Uploaded by

Atom Hack
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Assigmment 1

The document contains two Python programming assignments. The first program separates even and odd elements from a list into two new lists. The second program sorts a list of strings by the length of each string.

Uploaded by

Atom Hack
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Assignments

1. Write a program to put Even and Odd elements into two different lists

Program to Merge two lists and sort it

def merge_list(lst1):
lst2 = []
lst3 = []
lst4 = []
for x in lst1:
if x % 2 == 0:
lst2.append(x)
else:
lst3.append(x)
print("Even elements : ", lst2)
print("Odd elements : ", lst3)

lst4 = lst2 + lst3


lst4.sort()
print("Mearged and Sorted Lists : ", lst4)

lst1 = [int(lst1) for lst1 in input("Enter Any Numbers : ").split(" ")]


merge_list(lst1)

Output:

2. program to sort the list according to the length of the elements


lst = [str(lst) for lst in input("Enter the elements for the list : ").split(" ")]

lst.sort(key = len)
print(lst)

Output :

You might also like