-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexicographic order.py
43 lines (33 loc) · 1.05 KB
/
lexicographic order.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 26 17:09:25 2020
@author: shrey
"""
a=input().split(",")#taking addresses as input splitted by comma
l=[]
count=0
temp=0
b=0
l.append(a[0])#appending the first element in a to l
for i in range(len(a)):
for j in range(len(l)):
if a[i]>l[j]:
count=count+1
if a[i]<l[j]:
temp=temp-1
b=j
if count>0 and temp==0:
l.append(a[i])#if a number is greater than all elements in the list,
#append it at the last
count=0
if count==0 and temp<0:
l.insert(0,a[i])#if a number is smaller than all elements in the list, insert it at
#the first position
temp=0
if count>0 and temp<0:
l.insert(b,a[i])#if a number is less than and greater than particular values
#then add it to the list before the number it is lesser than
b=0
count=0
temp=0
print(l)