| | I have a list of integers. I want to know whether the number 13 appears in it and, if so, where. Do I have to search the list twice, ... | I have a list of elements with attrs: parent, level, is_leaf_node, is_root_node, is_child_node.
I want to convert this list to hierarchy dict.
Example of output dict:
{
...
| i have a file with information in the pattern of:
.343423 1
.434322 1
.453434 1
.534342 1
Equal size each line and row in sorted order..I have a variable "a" with a value and need ... | For python, I could use unpacking arguments as follows.
def hello(x, *y, **z):
print 'x', x
print 'y', y
print 'z', z
hello(1, *[1,2,3], ...
| In Python, the original dict list is as follows:
orig = [{'team': 'team1', 'other': 'blah', 'abbrev': 't1'},
{'team': 'team2', 'other': 'blah', 'abbrev': 't2'},
...
| I have a list [5, 90, 23, 12, 34, 89] etc where every two values should be a (ranked) list in the dictionary.
So the list above would become {1: [5, 90], ... | I'd like to take a string containing tuples that are not well separated and convert them into a dictionary.
s = "banana 4 apple 2 orange 4"
d = {'banana':'4', 'apple':'2', 'orange':'4'}
I'm running ... | | I'm trying to see whether nodes reside within the volume of a sphere, and add the node id to a list. However, the efficiency of the algorithm is incredibly slow and ... | How to convert list of dict to dict. Below is the list of dict
data = [{'name': 'John Doe', 'age': 37, 'sex': 'M'},
{'name': ...
| I have the following loop:
for row in rows:
print row.value('customer', 'name')
# print [customer for customer in customers if customer['name'] == row.value('customer', 'name')]
When I uncomment the second ... | I have a class object that stores some properties that are lists of other objects. Each of the items in the list has an identifier that can be accessed with the ... | I'd like to know the most elegant (and performant?) pattern to replace what I often code as:
names = []
for person in persons:
names.append(person.GetName())
I write this because it's how ... | I understand that they are both essentially the same thing, but in terms of style, which is the better (more Pythonic) one to use to create an empty list or dict?
... | I created a Python script with Python2.7 and it works fine. However, when I run the same script with Python2.6, I got a "SyntaxError: invalid syntax" error.
After investigating, the problem seems ... | I have a list:
d = [{'x':1, 'y':2}, {'x':3, 'y':4}, {'x':1, 'y':2}]
{'x':1, 'y':2} comes more than once I want to remove it from the list.My result should be:
d = [{'x':1, 'y':2}, ...
| T = {'a': {'c': 'A', 'path': '/c'}, 'e': {'c': 'E', 'path': '/e'}, 's': {'c': 'S', 'path': '/s'}}
I need all 'path' elements as a list. I know I can iterate through everything ... | I have a list of dict like this:
[{'value': 'apple', 'blah': 2}, {'value': 'banana', 'blah': 3} , {'value': 'cars', 'blah':4}]
I want ['apple', 'banana', 'cars']
Whats the best way to do this?
| I'd like to accept either one dict or a list of dicts as a function argument. So far, I've come up with the following, but I suspect I've missed something completely ... | I have a dictionary with a list as a value such as:
numlist = {'Person': ['2342342', '15:05']}
I pickle it.
outfile = open{"log.txt", "wb")
pickle.dump(numlist, outfile)
I unpickle it.
infile = open("log.txt", "rb")
pickle.load(infile)
How do I convert this ... | # Method one
array_a = []
a = {}
for i in range(5):
a = {}
a[str(i)] = i
array_a.append(a)
print(array_a)
# [{'0': 0}, {'1': 1}, {'2': ...
| I have this simple structure:
o = {
2: [0, 148, 149, 150, 151],
3: [0, 152, 153, 154, 155, 156],
4: [0, ...
| Hello, I'm trying to find the fastest way to convert an sql result into a dict or list. What i mean, for example: my sql result: contact_id, field_id, field_name, value sql_result=[[1, 1, 'address', 'something street'], [1, 2, 'telnumber', '1111111111'], [1, 3, 'email', 'something@something.net'], [2, 1, 'address','something stree'], [2, 3, 'email','something@something.net']] the dict can be: dict={1:['something street', '1111111111' , 'something@something.net'], 2:['something street', ... | Hi, I am new to python, i want to delete the any elemet from a dict of list. Say from the below example, i want to delete 'sona'. How can i achive this? dict_list = {'name': ['abhi', 'pankaj', 'sona', 'kajol']} Actually i am running a loop, where if i found any bad value in the above list then i want to ... | Hi evryone, I'm learning Python and I work on a little script at the moment. The script reads a TAB separated file with basically the following content format. ------------------- 1101,103,105,231 2102,203,234 1101,104 2102,400,236,345 ------------------- The script itterates over all the lines and, splits the line and creates two variables. (id,value) = line.split("/t") Then the script creates a dict where, id is ... | Read this and you will understand why. Code: Select all In [1]: for i in xrange(1,10): ...: for e in xrange(1,20): ...: print i, e ...: 1 1 1 2 1 3 1 4 1 5 1 6 1 7 ... | so I have a dictionary of user names and apps It goes like this: {"name1":["app1","app3"],"name2":["app2","app3","app5"].......} It runs my whole site by deciding what users have access to which apps. There are about ten to thirteen users in total. The problem is my javascript app list editor is returning a list like this: (["name1","app1"],["name1","app3"],["name2","app2"],["name2","app3"],["name2","app5"]...) I've been fighting with it for a few ... | Hi, I know this problem is pretty stupid, i got something like 4 kind of error trying to write this piece of code (Think python exercise).. But I'm still hopeful I got a typeerror Nonetype object is not iterable, Then an index error and then i probably wrote too many for loops (and chaging them into while loops wasn't helpful ...) ... | | |
|