I have this list of Unique items but i want the Fist item to be UG then EG and then rest order is ok
hello Alien,
I dont wanna put anything Random by myself as “UG” above. All these values in lists comes from its parameters.
Yes its working Alien. Thanks. But it would be much better if we dont give index number here becasue sometimes UG can not be on the same index and then this code could pick another item and place it to the front
4 Likes
ahahha Thanks Alien. I somehow did the job with your suggestion but this one is more to the point. Thanks alot for both solutions and i ll mark it both.
1 Like
I’m learning Python at the moment and noticed that there’s a null in the above list…
So:
myList = IN [0]
toFind = IN[1]
found = False
for i in range(len(myList)):
found = myList[i] == toFind
if found:
break
if found:
OUT = (i)
else:
OUT = ("absent")
Btw, this only finds the first of the type in the list.
another way in Python
solution in detail
lst = ["EG","1.06","2.06","UG","1.OG_H4", "2.04_H4"]
#get index of "UG"
idx = lst.index("UG")
#remove it and store it in variable
var = lst.pop(idx)
#add at the first index
lst.insert(0, var)
OUT = lst
which can be write in 1 line
lst = ["EG","1.06","2.06","UG","1.OG_H4", "2.04_H4"]
lst.insert(0, lst.pop(lst.index("UG")))
OUT = lst
2 Likes