I have a dict, which I need to pass key/values as keyword arguments.. For example..
d_args = {'kw1': 'value1', 'kw2': 'value2'}
example(**d_args)
This works fine, but if there are values in the d_args dict ... |
How do I run a function on a loop so all the results go straight into a list and is there a way to run a function which acts on all ... |
I get the feeling this is probably something I should know but I can't think of it right now. I'm trying to get a function to build a list where the ... |
Is there an easy way to be inside a python function and get a list of the parameter names?
For example:
def func(a,b,c):
print magic_that_does_what_I_want()
>>> func()
['a','b','c']
Thanks
|
I'm trying to call a function inside another function in python, but can't find the right syntax. What I want to do is something like this:
def wrapper(func, args):
...
|
I have a list of callback functions that I need to invoke when an event is fired.
Is this idiomatic python?
def first_callback(m):
print 'first ' + m
def second_callback(m):
print ...
|
I was writing a python function that looked something like this
def foo(some_list):
for i in range(0, len(some_list)):
bar(some_list[i], i)
so that it was called ... |
|
def getStuff(x):
return 'stuff'+x
def getData(x):
return 'data'+x
thefunctions = []
thefunctions.append("getStuff")
thefunctions.append("getData")
for i in thefunctions:
print i('abc')
Is this possible? Thank you.
|
I'm a little confusing when try something like this
b = [lambda x:x**i for i in range(11)]
When I then try b[1](2) I have 1024 as a result that is wrong. But when ... |
If i were to run this code:
def function(y):
y.append('yes')
return y
example = list()
function(example)
print(example)
Why would it return ['yes'] even though i am not directly changing the ... |
In Ruby, you can call Enumerable#any? on a enumerable object to see if any of its elements satisfies the predicate you pass in the block. Like so:
lst.any?{|e| pred(e) }
In ... |
I'm looking for a concise and functional style way to apply a function to one element of a tuple and return the new tuple, in Python.
For example, for the following input:
inp ...
|
I have two Python functions, both of which take variable arguments in their function definitions. To give a simple example:
def func1(*args):
for arg in args:
...
|
I'm building a simple interpreter in python and I'm having trouble handling differing numbers of arguments to my functions. My current method is to get a list of the commands/arguments as ... |
Is there anyway to know which functions exported from the dll througth python foreign function library -ctypes-
and if possible to know details about the exported functions throught ctypes.
if yes could someone ... |
I have code that looks something like this:
self.ui.foo.setEnabled(False)
self.ui.bar.setEnabled(False)
self.ui.item.setEnabled(False)
self.ui.item2.setEnabled(False)
self.ui.item3.setEnabled(False)
And I would like to turn it into something like this:
items = [foo,bar,item,item2,item3]
for elm in items:
self.ui.elm.setEnabled(False)
But obviously just having the ... |
I have made a class in which there are 3 functions.
- def maxvalue
- def min value
- def getAction
In the def maxvalue function, I have made a list of actions. I want that list ... |
Is there a way to get the argument names a function takes?
def foo(bar, buz):
pass
magical_way(foo) == ["bar", "buz"]
|
For example, if I have
a=[['a','b','c'],[1,2,3],['d','e','f'],[4,5,6]]
How can I get each element of a to be an argument of say, zip without having to type
zip(a[0],a[1],a[2],a[3])?
|
I have a line like this:
filter(lambda x: x == 1, [1, 1, 2])
Pylint is showing a warning:
W: 3: Used builtin function 'filter'
Why is that? is a list comprehension the recommended ... |
I was looking for an algorithm to replace some content inside a list with another. For instance, changing all the '0' with 'X'.
I found this piece of code, which works:
list ...
|
Sorry for such a silly question, but sitting in front of the comp for many hours makes my head overheated, in other words — I'm totally confused.
My task is to ... |
In python I defined functions:
def foo_1(p): return p + 1
def foo_2(p): return p + 1
def foo_3(p): return p + 1
def foo_4(p): return p + 1
def foo_5(p): return p + 1
I need ... |
How can I have a clean list of exceptions that a standard function/method can raise ? Without that, how can I anticipate the behavior of a function ?
Thanks.
|
>>> def test():
... a.remove(1)
>>> a = [1,2]
>>> test()
>>> print a
[2]
Why does a equal [2] rather than [1,2]?
|
How can I use a Python list (e.g. params = ['a',3.4,None]) as parameters to a function, e.g.:
def some_func(a_char,a_float,a_something):
# do stuff
|
How can I make this function take as input an arbitrary list size?
def ugly_function(lst):
for a in lst[0]:
for b in ...
|
I just recently switched to Komodo for Python programming, and I'm loving it so far. I love how if I type a function name, followed by the open-paren (, it ... |
can I call a list of functions and use list comprehension?
def func1():return 1
def func2():return 2
def func3():return 3
fl = [func1,func2,func3]
fl[0]()
fl[1]()
fl[2]()
I know I can do
for f in fl:
f()
but ... |
I have a list of numbers and I have to use a function to display them in celsius, they are in fahrenheit now.
nums = [30,34,40,36,36,28,29,32,34,44,36,35,28,33,29,40,36,24,26,30,30,32,34,32,28,36,24,32]
def fahrenToCel(c):
c ...
|
When I type the following into the interpreter I get the desired output behavior:
>>> x = (7, 2, 1, 1, 6, 2, 1, 2, 1, 2, 2, 6)
>>> y = list(x)
>>> ...
|
I have a multi-dimensional array that I am trying to feed into difflib.get_close_matches().
My array looks like this: array[(ORIGINAL, FILTERED)]. ORIGINAL is a string, and FILTERED is the ORIGINAL string with common ... |
Which one's a better way of doing list comprehension in python (in terms of computation time & cpu cycles).
In example (1) is the value f(r) evaluated in each iteration or ... |
Is it possible to display a list of all user functions in the IDLE session?
I can see them popping up in the autocomplete, so maybe there is other way to just ... |
How to pass a list as an argument to function in threading.Timer(...) ?
Please see the following code. I would like to pass nb[] as an argument
nb=['192.168.1.2', '192.168.1.3', '192.168.1.4']
ping_thread = threading.Timer(12.0, pingstarter, ...
|
Is there any equivalent 'LIKE' function(like in MySQL) for lists. for example;
This is my list:
abc = ['one', 'two', 'three', 'twenty one']
if I give the word "on", it should print the matching ... |
I want to pass function's list along with its parameters as a parameter in another function using Python. I know it is possible to pass function as a parameter,
but is it ... |
I am trying to loop through all the elements (8 of them) in my list, but my function is only providing me with 4 of them. This is for an application ... |
I'm looking for the best way to give a list of arguments to my function :
def myFunc(*args):
retVal=[]
for arg in args:
...
|
I have a function that takes an object as an argument and gives me a number. I wish to use this number as the key to sort my list.
If I were ... |
i would like to assign new values to the list i pass to my functions. At the case of get_p_values it works fine, but at `read_occupation' not (I get as an ... |
I want to get this function to work:
def getEvenNumbers (numbers):
bo = []
for num in numbers:
...
|
Is there a way that I can give python a list of values like [ 1, 3, 4.5, 1] and obtain a function that relates to those values? like y = ... |
Is there a way to achieve something like this in python?
another_function( function(x) {return 2*x} )
|
Ok, stupid python question: Is there syntax that allows you to expand a list into the arguments of a function call?
Example:
# trivial example function, not meant to do anything ...
|
i am using the itertools.product function. i have a 2-deep nested list, which is a list of iterables. i want to pass this to product function dont know how to ... |
I've been looking through a tutorial and book but I can find no mention of a built in product function i.e. of the same type as sum(), but I could not ... |
Mind you that python is my first language and I am a student but this isn't homework, I was just hoping someone could show me something I am curious about
I know ... |
|
|
Hi guys, I'm writing a Python class. his class has a function in it which accepts only one parameter. def find_content(content_type): .. .. .. .. I would like to limit the list of values that can be passed to the function. The value of content_type can be VIDEO, AUDIO, or IMAGE. What i currently do is let the user pass anything ... |
Hi, I use logging module in an application, and the handler to use for logging is specified in a configuration file. So in my script, I don't know which handler it's going to be used, so I use getattr to call the function to create the instance of the handler, e.g. handler= getattr(logging,opts['handler'])(opts['args']) where 'opts' is a dict with the configuration ... |
|
What kind of operation do you do with each checkbox? If it's just assigning a value, etc... Try this: Build a dictionary where keys are checkbox IDs (or checkboxes themselves, they should be hashable) and values being the value assigned. Then you can simply grab a value based on what checkbox was clicked. Another way might be to ignore checkbox events ... |
creating a list of values generated from a function by cvani Wed Aug 03, 2011 7:01 am Hi, I am trying to create a list of p_u values here. But it doesn't work. I can't figure out what mistake I have made. These functions would be called number of times depending on how many times the calculation is needed. But ... |
def D_theta1(t,theta1,theta2,w1,w2): print(w1) def D_theta2(t,theta1,theta2,w1,w2): print(w2) def D_w1(t,theta1,theta2,w1,w2): return (-g*3*math.sin(theta1)-g*math.sin((theta1-2*theta2)) -2*math.sin((theta1-theta2))*((w2**2) + ... |
I need to write code that takes an undetermined number of scores from the user until they type "done," computes the highest, lowest, and average scores. I'm supposed to use a loop for the user input, then pass the high/low/avg to each function. It's for an online class, and I think I get the individual aspects of it, but I can't ... |
Lists/Functions by marcaake Mon Jul 18, 2011 3:36 pm I need to write code that takes an undetermined number of scores from the user until they type "done," computes the highest, lowest, and average scores. I'm supposed to use a loop for the user input, then pass the high/low/avg to each function. It's for an online class, and I think ... |
Lets say I have a list: args = [1, 3] And I have the following method: def TestFunc(foo, bar) pass If I try to call TestFunc(args) I will get an error because python wants two parameters instead of one. Is there a way I can expand the parameter list so that I can call my function? Anthony |
from BeautifulSoup import BeautifulSoup import urlib2 imporrt urlen listOfUrls = urlen.getUrl() #import urls def returnstatment() bolag0 = urlib2.urlopen(listOfUrls[0]) start0 = bolag0.find(' | Aktie | +/- | +/- % | Köp | Sälj | Senast | Högst | Lägst | Antal | Tid | Bev.lista | | Köp Sälj |  | Ericsson ... | Hi! I got a problem with some lists. I need functions to make it's right, but i don't know what function i will take? Help? Code: Select all import urllib2 import sys, os, signal import urlen username = raw_input('MoneyMaker login password?: ') if username == "hello": print "Welcome to the MoneyMaker \nMoneyMaker is ON..." else: ... | Function to list Divisors and Common Even Divisors by Adi7 Tue Mar 22, 2011 9:12 am My objective is as follows: In the main section of the program, you will prompt the user for the two integers to use. To determine the divisors of an integer, n, you will have a function that receives an integer but does not ... | First time post, so bear with me if these questions are simple to solve. I am not at all familiar with Python language and hoping someone can help me out. I have a list of 7 numbers. I need to write a program that will do the following things: 1. Display the numbers in ascending order. 2. Display the numbers in ... | | I'm reading through these tutorials and this is confusing me. I create two types of list one initialized to None say for instance b_list = None. then another c_list = [] an empty list this block of text is taken from this site: http://python.net/~goodger/projects/pyc ... -variables //// Default Parameter Values This is a common mistake that beginners often make. Even more ... | Sorting lists by a specific field with sort function by ep123 Sat Mar 20, 2010 12:55 pm Hi I have created a program which takes in events and saves them to file then loads them up and displays each separate event on a separate line with all fields for each single event on one line with tabs between each of ... | | when you define a function, everything in the signature (not the function body) is evaluated and "bound" in the scope directly outside of the function (in this case, the global scope). That means that when you use a mutable object - like a list - in a signature, for each call to the function the same object will be used. So ... | | if i have a list and i want to work though it with a function, how do i output the results into a new list? i'm getting messy things happening with lots of seperate print things, i can't keep working with the output very well. just as an example, if i want to double all the numbers in a list of ... | I'm trying to write 3 functions. 1) to read the data from a file into a list. 2) to sort the list . 3) to write the list to a file. Do I want to pass a list or return a list. Function 1) would create the list but how does Function 2 and Function 3 get the list? Can someone ... | >>> myargs={'x':1., 'a':2., 'b':3.} >>> a=myargs.copy() >>> a.pop('a') 2.0 >>> lambda z:f(z, **a) at 0x758b0> >>> (lambda z:f(z, **a))(1.) Traceback (most recent call last): File "", line 1, in File "", line 1, in TypeError: f() got multiple values for keyword argument 'x' >>> | import random suits = [ 'clubs', 'hearts', 'diamonds', 'spades' ] values = [ '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A' ] deck = [] def initDeck(myDeck): myDeck[:] = [ (x,y) for x in values for y in suits ] def easyShuffle(myDeck): random.shuffle(myDeck) initDeck(deck) print "fresh deck: ",deck,'\n\n' easyShuffle(deck) print ... | Well, I guess you learn something new everyday ;) I've been programming with Python for 5 years and always assumed that any changes made to anything sent to a function were only local unless you declare the variable global. I thought I read it in a book back when I learned it, but I can't say for sure... and since you ... | Hello, I was learning python at home and I have this quick question, perhaps clarification: Code: Select all #!/usr/bin/python #global vars def function1(): global g_var1 print g_var1 g_var1 = "Changing the global var" print g_var1 global g_list ... | 16 print type(seq) ---> 17 if seq[0]==0: 18 if k==0: 19 integralen=Trapetz(a,b,h) : 'int' object is unsubscriptable ... | Thanks for the response. More specific? Sure. I want one method in my module that will call all the other functions in the module, with out actually knowing what the other functions are. If I call dir() from within a method it list's its namespace. I want the parent of the method's namespace. For example: If we have module1 with the ... | default argument values are bound to the function when the function is defined. it isn't a global variable because it isn't in globals() -- it's in listTest.func_defaults. i don't know why the dev team chose to make arguments append to the list instead of re-bind it, but that's what happens. yeah, i think it is a wart, but i really don't ... | |
|