List

python iterate over a list and remove any duplicates found within lists inside a dictionary and remove the duplicates


i have a list of numbers and a dictionary with names(key) and numbers(values)
i need to iterate over the list called lotto and and then check them against the values of the names in the dictionary and if i get a match remove that number from the dictionary value.

heres what i have so far but it just prints out the origanal dictionary keys and values

players = {'ray': [1,2,3,6,7,8,], 'al':[1,2,3,4,8,9,]}
lotto =[1,2,3,4,5,6,]

for i in players.values():  
    if i in lotto:
       players.values.remove(i)  

print (players)

any help appriciated



لینک منبع

php – Echo gives multiple ‘columns’ instead of one list


I wrote the following code:

foreach ($key['options'] as $options) {
$contents = str_replace("[OPTION]",$options['text'], $contents);
}

$result= '';

foreach ($key['motor'] as $motor) {
$nm = $motor['name'];
$cnt = $motor['count'];
$result .= $cnt ." " .$nm. " ";
}

echo $result;

$paginas .= $contents;

echo $paginas;

I have a (test) website about cars that contains 3 columns next to each other. Per car one column with the information I request via MySQL. That worked fine.

Now with the $result, I’d like to add more information to these columns, but there are multiple options per car. Instead of listing all the $results in one column, it makes for each item a new column.

My goal is to get one overview where all the results from the $result are listed in 1 column.

Anyone a clue how I can solve this?



لینک منبع

python – List all base classes in a hierarchy of given class?


See the __bases__ property available on a python class, which contains a tuple of the bases classes:

>>> def classlookup(cls):
...     c = list(cls.__bases__)
...     for base in c:
...         c.extend(classlookup(base))
...     return c
...
>>> class A: pass
...
>>> class B(A): pass
...
>>> class C(object, B): pass
...
>>> classlookup(C)
[<type 'object'>, <class __main__.B at 0x00AB7300>, <class __main__.A at 0x00A6D630>]



لینک منبع

javascript – Sync custom countries list and Google Maps API data


I have next issue.

There is a catalog with an items, which are placed somewhere physically. Admins
are “placing” them via Google Maps API – pointing item placement on it. All data saved in DB.

On front I have a searchbox. Searchbox with available geooptions – continents, countries, states/regions, cities. It’s like list. And user can find some object just clicking on desired city,country etc – then moving to search results page obviously.

I’ve come to problem, that my list in searchbox should base on Google Maps place_id’s to provide search ability. But API doesn’t return any lists. It’s just returns one object or place.

While trying to solve puzzle, came to idea to have custom list from GeoNames.org for example. But how to get syncronized all cities and stuff with Google Maps data?

Suppose, that sync geoobjects via string names not the best option.

thx in advance



لینک منبع

In Tapestry how do I check, on the client side, what the size of a list is inside another object?


So I’m using Tapestry version 5.3.8. I have a list of objects, we’ll use Orders, and inside of each Order is a list of dates that this order has been placed. Orders can be placed again and thus will have a history. If there is only 1 order I don’t display a dropdown. If there is multiple reorders, I display a dropdown with the dates. I’m trying to check using if the list is greater than 1 in order to display the drop down. I’d like this to happen on the client side. New to Tapestry so I apologize for the simplicity of this question.

Order Request
List of Order Dates

Thanks for the help.



لینک منبع

python – Recursion can’t append list


Here I use a simplified code to demonstrate what I’ve encountered:

def recTry(inList):
    print(inList)
    if len(inList) < 10:
        recTry(inList.append(1))

I hope with recursion it’ll grow like [1], [1, 1], [1, 1, 1]
But actually run that will yield this:

>>> recTry([1])
[۱]
None
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in recTry
  File "<stdin>", line 3, in recTry
TypeError: object of type 'NoneType' has no len()

inList become None since the second recursion.
So How can I code to make the inList appended with each recursion?



لینک منبع

Find Index of an Object in a generic List in C#


I have a generic class

public class foo <T> where T:boo
{
  List<T> fooList;
}

Now there is a method of the foo class, which should return the index of an object of type boo.

public getIndex(boo booObject)
{
   int index = fooList.IndexOf(booObject);
}

Unfortunately this is not working, because booObject can’t be converted to Type T…

How can I get the the index???
Thanks in advance.



لینک منبع

Algorithm in javascript or python that takes a list of numbers and “groups” them into approximately similar size?


I am looking for an algorithm that takes 2 inputs:

۱) Number of desired groups.
۲) A list of numbers (that may have duplicates)

Output should be the desired groups (with the individual numbers from the original list in them).

How could I accomplish this?



لینک منبع

Making multiple output lists into one list [python]


I have this generator

def keys():
    objects = [{'1':True,'2':True,'3':False,'4':False,'5':True,'6':True}]
    rng = range(len(objects))
    clean = int(''.join(map(str, rng)))
    for keys, values in objects[clean].iteritems():
        if values == True:
            yield keys 

and then i want to get all the generator values, which I do using for loop

for i in keys():
    i= i.split()
    print i

and the output is :

['۱']
['۲']
['۵']
['۶']

is there a way I can add them to a single list?
like [[‘1’],[‘2’],[‘5’],[‘6’]] or most preferably [‘1′,’2′,’5′,’6’].
Would greatly appreciate your help. Thanks



لینک منبع