Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

60%
+1 −0
Challenges Coat of Many Colours

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...

posted 3y ago by General Sebast1an‭  ·  edited 3y ago by General Sebast1an‭

Answer
#4: Post edited by user avatar General Sebast1an‭ · 2021-10-03T00:34:37Z (about 3 years ago)
  • # [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):
  • &#9;c=[]
  • &#9;for i in a:
  • &#9;&#9;for j in b:
  • &#9;&#9;&#9;if j==i:c+=[i]
  • &#9;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 by user avatar General Sebast1an‭ · 2021-10-02T14:20:13Z (about 3 years ago)
  • # [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):
  • &#9;c=[]
  • &#9;for i in range(len(a)):
  • &#9;&#9;for j in range(len(b)):
  • &#9;&#9;&#9;if b[j]==a[i]:c.append(a[i])
  • &#9;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):
  • &#9;c=[]
  • &#9;for i in a:
  • &#9;&#9;for j in b:
  • &#9;&#9;&#9;if j==i:c+=[i]
  • &#9;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 by user avatar General Sebast1an‭ · 2021-09-06T00:26:39Z (about 3 years ago)
  • # [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):
  • &#9;c=[]
  • &#9;for i in range(len(a)):
  • &#9;&#9;for j in range(len(b)):
  • &#9;&#9;&#9;if b[j]==a[i]:c.append(a[i])
  • &#9;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):
  • &#9;c=[]
  • &#9;for i in range(len(a)):
  • &#9;&#9;for j in range(len(b)):
  • &#9;&#9;&#9;if b[j]==a[i]:c.append(a[i])
  • &#9;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 by user avatar General Sebast1an‭ · 2021-09-06T00:25:37Z (about 3 years ago)
# [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):
&#9;c=[]
&#9;for i in range(len(a)):
&#9;&#9;for j in range(len(b)):
&#9;&#9;&#9;if b[j]==a[i]:c.append(a[i])
&#9;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"