Post History
Python 3, 349 261 160 bytes a="re y gree br sc bla oc pe rub ol v f li go ch m cre cri si ro a le rus grey pu w pi or blu".split() def f(b):return[j for i in a for j in b if j[:len(i)]==i] T...
Answer
#4: Post edited
# [Python 3], <s>349</s> 261 bytes- <!-- language-all: lang-python -->
<pre><code>a="red yellow green brown scarlet black ochre peach ruby olive violet fawn lilac gold chocolate mauve cream crimson silver rose azure lemon russet grey purple white pink orange blue".split()def f(b):	c=[]	for i in a:		for j in b:			if j==i:c+=[i]	return c</code></pre>[Try it online!][TIO-ku9vr0ce]Golfed 88 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4668#comment-13979).- [Python 3]: https://docs.python.org/3/
[TIO-ku9vr0ce]: https://tio.run/##dVLBboMwDD2Xr7A4gVbtslslvqTqIaSmpAsJMtCK/Tx7TrpuqrRLHCfvOfZ7Gde5j@Fj20xTCp9pZe/jnS7CHKiVeA80WSOeZ2q9sZ8UbS9MIxvbkyztStG7G9PNRcV0BgTvgKRL9GeyfbTRm5lpMAtgVtgMWN0wRVR2/sZCEicm87WgrucB57JME4qhiZXGRUbPdO8diowuoAMx4cJoZ@HyfRq9m6u6OHNHXdXWh2Jnm@Op2HVRyJELZHCUsqtmrWY719G1adzBvjVHB7DwvEggu43iwlx11fFU18UzKZMc5b5Mb@5VKE1UnfIFiKFxpZ3nwK8I1QxXWednrUT4r1R6WpVFSDogJrmUDu1SY/AGMauFTRYJm6yxIvPDjxGSR4gPK5QKbdMBHFKAOpFo6sXvTMluxGw4NslYJf5Y/Xe69E@eWoGtv0e7yn/qMT8G374B "Python 3 – Try It Online"
- # [Python 3], <s>349</s> <s>261</s> 160 bytes
- <!-- language-all: lang-python -->
- a="re y gree br sc bla oc pe rub ol v f li go ch m cre cri si ro a le rus grey pu w pi or blu".split()
- def f(b):return[j for i in a for j in b if j[:len(i)]==i]
- [Try it online!][TIO-kuahp79m]
- Golfed 88 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4668#comment-13979). Golfed 81 bytes thanks to [**@celtschk**](https://codegolf.codidact.com/users/8056)'s [advice](https://codegolf.codidact.com/comments/thread/4680#comment-14010).
- [Python 3]: https://docs.python.org/3/
- [TIO-kuahp79m]: https://tio.run/##dVC7bsMwDNzzFYQnGyi6dAuQLwkyyAptM6FFgfID7s@7olK4QIBOpE7H4x3jNg0SvvbdXSpF2KBXRGgVkoeWHYiHiKBzC8KwQAdM0Av4AUbwecArQSJQAQdsxGQKG8QZVogEollmrj5TZJrq5nTHDrq6bc6K06zh@oAuUwgoZAFrH9a2QB08rmfGUFNzu1zotkelMNVdfb01zel4VOY3VB9V3oK5KN7tobKG6o0obF/m7lXwnZFT2teGzLIeWmXgP6myunOrlXWgySy471mLFUlYjDn/zDXOGtkAURd6axLxgmrM1@LfCEx5Itd82jGJKUcKzwKgG42AY4HzsRNOf5mEaTGBhYQLPrq5AH4QL@yKuyNdROeH41Z52g/FdvJOX@OWPwfffwA "Python 3 – Try It Online"
#3: Post edited
# [Python 3], 349 bytes- <!-- language-all: lang-python -->
<pre><code>a=["red","yellow","green","brown","scarlet","black","ochre","peach","ruby","olive","violet","fawn","lilac","gold","chocolate","mauve","cream","crimson","silver","rose","azure","lemon","russet","grey","purple","white","pink","orange","blue"]- def f(b):
- 	c=[]
	for i in range(len(a)):		for j in range(len(b)):			if b[j]==a[i]:c.append(a[i])- 	return c
- </code></pre>
[Try it online!][TIO-kt7wjd78]Uses functions, where a list is used as the function's argument. Basically, it figures out where the strings lie and adds the correct order under a new list. As defined from the challenge, empty lists are, by default, handled. All test cases are in the footer.- [Python 3]: https://docs.python.org/3/
[TIO-kt7wjd78]: https://tio.run/##dVLBboMwDD3DVyBOIFW77FaJL0EcQmpKupBEhrTqfp7FDoF1U0@G@NnPfs/uuYzWfK6raNoS4VKeyidobR/h44oAJsQe7YPiLAVqWOhFC/kVopUjQogOhBxDRN8/6VmrOz3flY34QXADrUIdNbaaiORopdViIegkPJdIBDFxVNNsmVXpOyA1tzMhxLdnTg0T59HPM5OEcYnceXSaAI9RcWunDM@KwlyBh/dQdvkFhmKo@vqcZ7JpuzwbLBaqUKZgYKXBVKKmNGdur5k@ZjI1FH1765pGtKo7yw/hHJhLRX91niEsHk0hV4fKLNVQtV1d5/vPoTCNdNr0j3L/AUbFthVj2Stik343L/bignetmHqzJomV1N3ETkbvou4qHrZE4m2FZPHh3yZ/Mvadbf9uZr@IX1eyb5cOLp1mOsTjRGn/sPj6Aw "Python 3 – Try It Online"
- # [Python 3], <s>349</s> 261 bytes
- <!-- language-all: lang-python -->
- <pre><code>a="red yellow green brown scarlet black ochre peach ruby olive violet fawn lilac gold chocolate mauve cream crimson silver rose azure lemon russet grey purple white pink orange blue".split()
- def f(b):
- 	c=[]
- 	for i in a:
- 		for j in b:
- 			if j==i:c+=[i]
- 	return c
- </code></pre>
- [Try it online!][TIO-ku9vr0ce]
- Golfed 88 bytes thanks to [**@user**](https://codegolf.codidact.com/users/53837)'s [advice](https://codegolf.codidact.com/comments/thread/4668#comment-13979).
- [Python 3]: https://docs.python.org/3/
- [TIO-ku9vr0ce]: https://tio.run/##dVLBboMwDD2Xr7A4gVbtslslvqTqIaSmpAsJMtCK/Tx7TrpuqrRLHCfvOfZ7Gde5j@Fj20xTCp9pZe/jnS7CHKiVeA80WSOeZ2q9sZ8UbS9MIxvbkyztStG7G9PNRcV0BgTvgKRL9GeyfbTRm5lpMAtgVtgMWN0wRVR2/sZCEicm87WgrucB57JME4qhiZXGRUbPdO8diowuoAMx4cJoZ@HyfRq9m6u6OHNHXdXWh2Jnm@Op2HVRyJELZHCUsqtmrWY719G1adzBvjVHB7DwvEggu43iwlx11fFU18UzKZMc5b5Mb@5VKE1UnfIFiKFxpZ3nwK8I1QxXWednrUT4r1R6WpVFSDogJrmUDu1SY/AGMauFTRYJm6yxIvPDjxGSR4gPK5QKbdMBHFKAOpFo6sXvTMluxGw4NslYJf5Y/Xe69E@eWoGtv0e7yn/qMT8G374B "Python 3 – Try It Online"
#2: Post edited
- # [Python 3], 349 bytes
- <!-- language-all: lang-python -->
- <pre><code>a=["red","yellow","green","brown","scarlet","black","ochre","peach","ruby","olive","violet","fawn","lilac","gold","chocolate","mauve","cream","crimson","silver","rose","azure","lemon","russet","grey","purple","white","pink","orange","blue"]
- def f(b):
- 	c=[]
- 	for i in range(len(a)):
- 		for j in range(len(b)):
- 			if b[j]==a[i]:c.append(a[i])
- 	return c
- </code></pre>
- [Try it online!][TIO-kt7wjd78]
Uses functions, where a list is used as the input. Basically, it figures out where the strings lie and adds the correct order under a new list. As defined from the challenge, empty lists are, by default, handled. All test cases are in the footer.- [Python 3]: https://docs.python.org/3/
- [TIO-kt7wjd78]: https://tio.run/##dVLBboMwDD3DVyBOIFW77FaJL0EcQmpKupBEhrTqfp7FDoF1U0@G@NnPfs/uuYzWfK6raNoS4VKeyidobR/h44oAJsQe7YPiLAVqWOhFC/kVopUjQogOhBxDRN8/6VmrOz3flY34QXADrUIdNbaaiORopdViIegkPJdIBDFxVNNsmVXpOyA1tzMhxLdnTg0T59HPM5OEcYnceXSaAI9RcWunDM@KwlyBh/dQdvkFhmKo@vqcZ7JpuzwbLBaqUKZgYKXBVKKmNGdur5k@ZjI1FH1765pGtKo7yw/hHJhLRX91niEsHk0hV4fKLNVQtV1d5/vPoTCNdNr0j3L/AUbFthVj2Stik343L/bignetmHqzJomV1N3ETkbvou4qHrZE4m2FZPHh3yZ/Mvadbf9uZr@IX1eyb5cOLp1mOsTjRGn/sPj6Aw "Python 3 – Try It Online"
- # [Python 3], 349 bytes
- <!-- language-all: lang-python -->
- <pre><code>a=["red","yellow","green","brown","scarlet","black","ochre","peach","ruby","olive","violet","fawn","lilac","gold","chocolate","mauve","cream","crimson","silver","rose","azure","lemon","russet","grey","purple","white","pink","orange","blue"]
- def f(b):
- 	c=[]
- 	for i in range(len(a)):
- 		for j in range(len(b)):
- 			if b[j]==a[i]:c.append(a[i])
- 	return c
- </code></pre>
- [Try it online!][TIO-kt7wjd78]
- Uses functions, where a list is used as the function's argument. Basically, it figures out where the strings lie and adds the correct order under a new list. As defined from the challenge, empty lists are, by default, handled. All test cases are in the footer.
- [Python 3]: https://docs.python.org/3/
- [TIO-kt7wjd78]: https://tio.run/##dVLBboMwDD3DVyBOIFW77FaJL0EcQmpKupBEhrTqfp7FDoF1U0@G@NnPfs/uuYzWfK6raNoS4VKeyidobR/h44oAJsQe7YPiLAVqWOhFC/kVopUjQogOhBxDRN8/6VmrOz3flY34QXADrUIdNbaaiORopdViIegkPJdIBDFxVNNsmVXpOyA1tzMhxLdnTg0T59HPM5OEcYnceXSaAI9RcWunDM@KwlyBh/dQdvkFhmKo@vqcZ7JpuzwbLBaqUKZgYKXBVKKmNGdur5k@ZjI1FH1765pGtKo7yw/hHJhLRX91niEsHk0hV4fKLNVQtV1d5/vPoTCNdNr0j3L/AUbFthVj2Stik343L/bignetmHqzJomV1N3ETkbvou4qHrZE4m2FZPHh3yZ/Mvadbf9uZr@IX1eyb5cOLp1mOsTjRGn/sPj6Aw "Python 3 – Try It Online"
#1: Initial revision
# [Python 3], 349 bytes <!-- language-all: lang-python --> <pre><code>a=["red","yellow","green","brown","scarlet","black","ochre","peach","ruby","olive","violet","fawn","lilac","gold","chocolate","mauve","cream","crimson","silver","rose","azure","lemon","russet","grey","purple","white","pink","orange","blue"] def f(b): 	c=[] 	for i in range(len(a)): 		for j in range(len(b)): 			if b[j]==a[i]:c.append(a[i]) 	return c </code></pre> [Try it online!][TIO-kt7wjd78] Uses functions, where a list is used as the input. Basically, it figures out where the strings lie and adds the correct order under a new list. As defined from the challenge, empty lists are, by default, handled. All test cases are in the footer. [Python 3]: https://docs.python.org/3/ [TIO-kt7wjd78]: https://tio.run/##dVLBboMwDD3DVyBOIFW77FaJL0EcQmpKupBEhrTqfp7FDoF1U0@G@NnPfs/uuYzWfK6raNoS4VKeyidobR/h44oAJsQe7YPiLAVqWOhFC/kVopUjQogOhBxDRN8/6VmrOz3flY34QXADrUIdNbaaiORopdViIegkPJdIBDFxVNNsmVXpOyA1tzMhxLdnTg0T59HPM5OEcYnceXSaAI9RcWunDM@KwlyBh/dQdvkFhmKo@vqcZ7JpuzwbLBaqUKZgYKXBVKKmNGdur5k@ZjI1FH1765pGtKo7yw/hHJhLRX91niEsHk0hV4fKLNVQtV1d5/vPoTCNdNr0j3L/AUbFthVj2Stik343L/bignetmHqzJomV1N3ETkbvou4qHrZE4m2FZPHh3yZ/Mvadbf9uZr@IX1eyb5cOLp1mOsTjRGn/sPj6Aw "Python 3 – Try It Online"