For a list ["foo", "bar", "baz"] and an item in the list "bar", how do I get the index and values for the other two items only knowing that "bar" is in the list?   In other words, how do I obtain the index &amp; value for the item before and the item after "bar"?
2050
Given a list ["foo", "bar", "baz"] and an item in the list "bar", how do I get its index (1) in Python?
63040
I want to get the picklist values of a picklist field in Apex.  I use the someFieldResult.getPicklistValues(); function and that works fine. This gives me all the picklist values, in alphabetic order (e.g. Alpha, Beta, Gamma).  However, I want to have those values in the order they were entered (e.g. Gamma, Alpha, Beta). How to do that?
64500
Currently, I'm trying to get a method in Python to return a list of zero, one, or two strings to plug into a string formatter, and then pass them to the string method. My code looks something like this:  class PairEvaluator(HandEvaluator):   def returnArbitrary(self):     return ('ace', 'king')  pe = PairEvaluator() cards = pe.returnArbitrary() print('Two pair, {0}s and {1}s'.format(cards))   When I try to run this code, the compiler gives an IndexError: tuple index out of range. How should I structure my return value to pass it as an argument to .format()?
79783
how can i copy values from one column to another? I'm using a workflow but i cant see the option "Copy List Item"   ps: I'm using Sharepoin On-line
10523
I know how to do it normally, but I could swear that you could fill out out like a[0] = {0,0,0,0}; How do you do it that way? I did try Google, but I didn't get anything helpful.
2624
Is there any way I can separate a List&lt;SomeObject&gt; into several separate lists of SomeObject, using the item index as the delimiter of each split?  Let me exemplify:  I have a List&lt;SomeObject&gt; and I need a List&lt;List&lt;SomeObject&gt;&gt; or List&lt;SomeObject&gt;[], so that each of these resulting lists will contain a group of 3 items of the original list (sequentially).  eg.:   Original List: [a, g, e, w, p, s, q, f, x, y, i, m, c] Resulting lists: [a, g, e], [w, p, s], [q, f, x], [y, i, m], [c]   I'd also need the resulting lists size to be a parameter of this function.
94608
I have a list . I want select items of list with a special quary.(get items that created with current user). Then get count of items.  I use this code for get current user :  function Initialize() {     context = new SP.ClientContext.get_current();     web = context.get_web();    var currentUser = web.get_currentUser();    alert(currentUser);     currentUser.retrieve();     context.load(web);     context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod),           Function.createDelegate(this, this.onFailureMethod)); }  function onSuccessMethod(sender, args) {     var userObject = web.get_currentUser();     alert('User name:' + userObject.get_title() + '\n Login Name:' +               userObject.get_loginName()); } function onQueryFailed(sender, args) {     alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace()); }   But don't get current user.  and use this code for get items of list.   function Initialize() {     clientContext = new SP.ClientContext.get_current();     web = clientContext.get_web();      var list = web.get_lists().getByTitle("Sends");     var camlQuery = new SP.CamlQuery();     var q = "&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name='CreatedUser' /&gt;&lt;Value Type='User'&gt;CurrentUser&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;";     camlQuery.set_viewXml(q);     this.listItems = list.getItems(camlQuery);      clientContext.load(listItems, 'Include(ID)');      clientContext.executeQueryAsync(Function.createDelegate(this, this.onListItemsLoadSuccess),      Function.createDelegate(this, this.onQueryFailed)); } function onListItemsLoadSuccess(sender, args) {     var count = 0;       count = this.listItems.get_count();             }  function onQueryFailed(sender, args) {     alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace()); }
24071
I'm trying to understand Python's approach to variable scope. In this example, why is f() able to alter the value of x, as perceived within main(), but not the value of n?  def f(n, x):     n = 2     x.append(4)     print('In f():', n, x)  def main():     n = 1     x = [0,1,2,3]     print('Before:', n, x)     f(n, x)     print('After: ', n, x)  main()   Output:  Before: 1 [0, 1, 2, 3] In f(): 2 [0, 1, 2, 3, 4] After:  1 [0, 1, 2, 3, 4]
112773
I need to be able to take a string like:  '''foo, bar, "one, two", three four'''   into:  ['foo', 'bar', 'one, two', 'three four']   I have an feeling (with hints from #python) that the solution is going to involve the shlex module.
53456
What is the difference between:  some_list1 = [] some_list1.append("something")   and  some_list2 = [] some_list2 += ["something"]
410
I needed to create a list of lists in Python, so I typed the following: my_list = [[1] * 4] * 3  The list looked like this: [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]    Then I changed one of the innermost values: my_list[0][0] = 5  Now my list looks like this: [[5, 1, 1, 1], [5, 1, 1, 1], [5, 1, 1, 1]]    which is not what I wanted or expected. Can someone please explain what's going on, and how to get around it?
1457
I have a list of 2-item tuples and I'd like to convert them to 2 lists where the first contains the first item in each tuple and the second list holds the second item.  For example:  original = [('a', 1), ('b', 2), ('c', 3), ('d', 4)] # and I want to become... result = (['a', 'b', 'c', 'd'], [1, 2, 3, 4])   Is there a builtin function that does that?
99659
I'd like to split strings like these  'foofo21' 'bar432' 'foobar12345'   into  ['foofo', '21'] ['bar', '432'] ['foobar', '12345']   Does somebody know an easy and simple way to do this in python?
43325
Former and latter are valid only when there are two choices.  If I have a list of more than two items, is there an elegant way to say the first one or the last one?
82341
example:  a_list = [1, 2, 3] a_list.len() # doesn't work len(a_list) # works   Python being (very) object oriented, I don't understand why the 'len' function isn't inherited by the object.  Plus I keep trying the wrong solution since it appears as the logical one to me
115669
Is it possible to start lists at a certain number, or alternatively, continue a previous list? I want something like this:  Pets  You could get a cat  Or you could get a dog   Or some less legal options  A tiger  A bald eagle   And of course, if it doesn't have to be real  A leprechaun   But I want to continue the number, so the last item is 5. Can I do this, and if so, how?
12971
I have about 10million values that I need to put in some type of look up table, so I was wondering which would be more efficient a list or dict?  I know you can do something like this for both:  if something in dict_of_stuff:     pass   and  if something in list_of_stuff:     pass   My thought is the dict will be faster and more efficient.  Thanks for your help.  EDIT 1  Little more info on what I'm trying to do.  .  I'm making a look up table to see if a value calculated has all ready been calculated.   EDIT 2  Efficiency for look up.  EDIT 3  There are no values assosiated with the value...so would a set be better?