## [Solved] Check to see if two lists have the same value at the same index, if so return the index. If not return -1

Introduction Solution I think a cleaner answer uses the built-in enumerate and zip functions: Dlist = [17,13,10,6,2] Ilist = [5,9,10,15,18] def seqsearch(DS,IS): for idx, (d, s) in enumerate(zip(DS, IS)): if d == s: return f”Yes! Found at index = {idx}” return “No!\n-1” print(seqsearch(Dlist,Ilist)) It’s unclear whether you want to return just the first index, or … Read more

## [Solved] Proper if..else syntax in Python

The correct syntax is if condition: # stuff elif other: # stuff elif some_other: # stuff else: # stuff Note that else does not get any explicit condition, it is the catch-all if none of the above conditions were True. 3 solved Proper if..else syntax in Python

## [Solved] How to transform a slice to a list of index in python? [closed]

You can use the indices method of the slice to generate a tuple that can be passed to range. You need to know the length of your instance though. For example: >>> sl = slice(2) # or wherever you get that from >>> length = 100 >>> list(range(*sl.indices(length))) [0, 1] 5 solved How to transform … Read more

## [Solved] how to find the maximum and minimum index of an element in a vector? [closed]

@cauchy: a map of pairs would be slower and more complex than it needs to be. Dumping the results to stdout actually takes more lines than a simple solution: // assuming compiler doesn’t support initialization lists for std::vector: int ai[] = { 1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, … Read more

## [Solved] Find index of returned list result C#

As the error states, it cannot convert from ‘System.Collections.Generic.List’ to ‘string’. However I never knew the function SingleOrDefult() existed. All credit to @maccettura even though he didn’t know what I was trying to do! xD Code change below for the answer: List<string> listFrom = new List<string>(); //Contains a list of strings List<string> listTo = new … Read more

## [Solved] Replace list object based on indexes of another list (Python)

You can get all of the indices whose value is x using a list comprehension: indices = [i for i, elem in enumerate(word) if elem == x] So you would have: >>> word = [“p”, “y”, “t”, “h”, “o”, “n”] status = [“_”, “_”, “_”, “_”, “_”, “_”] >>> >>> word [‘p’, ‘y’, ‘t’, ‘h’, … Read more

## [Solved] Matlab index error

I don’t even know how that code could even run. x is not defined anywhere and you suddenly are starting to use it in your for loop at the beginning. My guess is that you have some code defined somewhere earlier on, those iterations start happening and then once those iterations end, this function runs. … Read more

## [Solved] How do I make a default page for my website application with php?

To be true, I didn’t understand a reason why you want to do it, but anyway. But if I were you, I would make next steps Configure Apache/Nginx/or what you’re using for your website/ to process all your request through your default page(index.php or something like that) In index.php you need to understand what page … Read more

## [Solved] MySQL create index …performance issues [closed]

Check the MySQL slow query log to identify which query(ies) are causing the delay, then run EXPLAIN on them to see which (if any) indexes are being used. If you see that indexes are not being used, consider adding indexes to relevant columns. Such columns would be those used in WHERE and JOIN clauses. For … Read more

## [Solved] Creating a list that gives a specific value at even indexes and another value at odd indexes

Literally write it as you would say it! >>> [‘a’ if i % 2 else ‘b’ for i in range(10)] [‘b’, ‘a’, ‘b’, ‘a’, ‘b’, ‘a’, ‘b’, ‘a’, ‘b’, ‘a’] 2 solved Creating a list that gives a specific value at even indexes and another value at odd indexes

## [Solved] How to add indexes with a for loop from a multidimensional array using C#?

You need one more array, instead of four separate variables. This will make it easy to pick only (the right) one of the totals to update in the inner loop. Otherwise, all four scores will always get the score of the final golfer, since the inner loop currently sets all four variables. It will look … Read more

## [Solved] String out of index

Different methods can be used for removing leading and trailing spaces, for converting multiple spaces to one and to remove spaces before exclamation mark, comma etc: mystr = ” Hello . To , the world ! ” print(mystr) mystr = mystr.strip() # remove leading and trailing spaces import re # regex module mystr = re.sub(r’\s+’,” … Read more

## [Solved] Why does indexing into a list with list[n] instead of list[[n]] in R not do what you would expect? [duplicate]

Because in general l[n] returns a sublist (possibly of length one), whereas l[[n]] returns an element: > lfile[2] [[1]] [1] “file2.xls” # returns SUBLIST of length one, not n’th ELEMENT > lfile[[2]] [1] “file2.xls” # returns ELEMENT From R intro manual: 6.1 Lists: It is very important to distinguish Lst[[1]] from Lst[1]. ‘[[…]]’ is the … Read more

## [Solved] Undefined index (PHP)

It’s ternary. The syntax is var = (true) ? trueValue : falseValue; It’s the same as this: if ( empty(\$_POST[‘code’]) ) { \$code = null; } else { \$code = \$_POST[‘code’]; } solved Undefined index (PHP)

## [Solved] python: index of list1 equal to index of list2 [duplicate]

well what the comments said and change it like the following too : id = [1, 2, 3, 4, 5, 6] name = [‘sarah’, ‘john’, ‘mark’, ‘james’, ‘jack’] userid = int(input(‘enter user ID: ‘)) if userid in id: ind = id.index(userid) #notice this statement is inside the if and not outside print(name[ind]) else: print(“wrong id”) … Read more