Need to get following output : `<<<<<>>>===` from Input `str1='<><<>>=<==<‘` using python

  python, string

I have a scenario where i am trying to print the input in sequence like below:

  • First need to print less than symbol
  • then Greater than symbol
  • after then equal to symbol

As I know only below approach to get the Output, is there any concise approach to get the expected output with few lines of code

I am not aware of any another approach than below , if any other approach solution is appreciated

My Code:

str1='<><<>>=<==<'
c=[]
e=[]
f=[]
d=[]
for a in str1:
    if a=="<":
        c.append(a)
for i in str1:
    if i==">":
        e.append(i)
for y in str1:
    if y=="=":
        f.append(y)
d=c+e+f
print(d)

Expected Output :

<<<<<>>>===

Source: Python Questions

LEAVE A COMMENT