4
$\begingroup$

To make a list of the letters at even-numbered position in Alphabet, I wrote this code:

Select[Alphabet[], EvenQ[Flatten[Position[Alphabet[], #]]] &]

But it does not work. Where did I go wrong?

$\endgroup$
8
  • 1
    $\begingroup$ As one begins learning Mathematica executing smaller parts of the overall function will give strong hints as to what might not be working as expected/desired. For example, Flatten[Position[Alphabet[], "a"]] gets you {1} and not 1. $\endgroup$
    – JimB
    Feb 15, 2022 at 3:10
  • $\begingroup$ @JimB But EvenQ[{1}] will show [False]. So, it shouldn't influence the answer. $\endgroup$
    – Y. zeng
    Feb 15, 2022 at 3:12
  • $\begingroup$ With that you get {False} and what you need is just plain False. $\endgroup$
    – JimB
    Feb 15, 2022 at 3:13
  • $\begingroup$ How about Select[Alphabet[], EvenQ[Flatten[Position[Alphabet[], #]]][[1]] &]. $\endgroup$
    – JimB
    Feb 15, 2022 at 3:14
  • $\begingroup$ @JimB Thank you. You are so clever. Should I close the question. I fear somebody will vote this question to close. $\endgroup$
    – Y. zeng
    Feb 15, 2022 at 3:17

2 Answers 2

13
$\begingroup$

Much simpler solution:

Alphabet[][[1 ;; All ;; 2]]
Alphabet[][[2 ;; All ;; 2]]
$\endgroup$
1
  • $\begingroup$ Alphabet[][[1 ;; ;; 2]] is equivalent and slightly shorter. $\endgroup$
    – bbgodfrey
    Feb 16, 2022 at 19:20
1
$\begingroup$

I've used Range to determine the sequence.

Alphabet[][[Range[1, 26, 2]]] for odd positions, for even positions Alphabet[][[Range[2, 26, 2]]]

$\endgroup$
1
  • $\begingroup$ This appraoch is very similar to the one already given. $\endgroup$
    – bbgodfrey
    Feb 16, 2022 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.