Mathematica: Position of elements in a list

  • Mathematica
  • Thread starter Sarah rob
  • Start date
  • #1
16
0
If I have a list say
li = {18, 22, 4, 10}
and I want to add for example 7 to this list
Join[li, {7}] to get {18, 22, 4, 10, 7},
can I insert the 7 after the 4, to get {18, 22, 4, 7, 10},
I cant just use Sort[ {18, 22, 5, 10, 7}] as I don' t want to change the order of the whole list???
 

Answers and Replies

  • #3
16
0
Thanks for that SredniVashtar with regards to position I need to make some kind of rule for n, I tried liss = 7 - li to get {-11, -15, 3, -3}

But I come up with difficulties because if I had 11 -li which gives me {-7, -11, 7, 1} I need to find the position of the smallest positive number
 
  • #4
192
41
Not sure what you are trying to accomplish.
If your list has non-negative numbers only, in the first place, why not using Min to find the smallest entry?

Position[ li , Min[li] ]

Perhaps you have to treat zeros in a special manner?
 
Last edited:

Related Threads on Mathematica: Position of elements in a list

Replies
4
Views
5K
Replies
1
Views
2K
Replies
22
Views
2K
Replies
3
Views
15K
  • Last Post
Replies
4
Views
2K
Replies
1
Views
2K
Replies
5
Views
4K
Replies
2
Views
836
Replies
1
Views
2K
Top