How to Find List Tuples with Encoding Range in Python


In this example, we will learn how to find all the elements in the tuple list for the fixed encoding rang with Python.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

a = [('a','48CS003'), ('b','48CS210'), ('c','48CS155'), ('d','48CS050'), ('e','48CS032'), ('f','48CS098')]
lowerLimit = input("Please input roll number lower limit (three digits starting with 48CS): ")
upperLimit = input("Please input roll number upper limit (three digits starting with 48CS): ")
low = '48CS' + lowerLimit
up = '48CS' + upperLimit
b = [i for i in a if i[1] > low and i[1] < up]
print(b)

Output:

Please input roll number lower limit (three digits starting with 48CS): 010
Please input roll number upper limit (three digits starting with 48CS): 100
[('d', '48CS050'), ('e', '48CS032'), ('f', '48CS098')]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments