I wonder what is the time complexity of pop method of list objects in Python (in CPython particulary). Also does the value of N for list.pop(N) affects the complexity?
... |
I have a list of booleans where occasionally I reset them all to false. After first writing the reset as:
for b in bool_list:
b = False
I found it ... |
Using Python, I'd like to compare every possible pair in a list.
Suppose I have
my_list = [1,2,3,4]
I'd like to do an operation (let's call it foo) on every combination of 2 elements ... |
I have an array with a set of elements. I'd like to bring a given element to the front but otherwise leave the order unchanged. Do folks have suggestions ... |
I have the following code in Python:
def point_to_index(point):
if point not in points:
points.append(point)
return points.index(point)
This code is ... |
What is an efficient way to find the most common element in a Python list?
My list items may not be hashable so can't use a dictionary.
Also in case of draws the ... |
I want to do this. I have two python lists, one larger than the other and I want to know is there is a way to check if the elements of ... |
|
Let's say I have a list somewhere called majorPowers which contain these two lists:
axis=["germany","italy","japan"]
allies=["russia","uk","us"]
I'd like to insert each of the elements of these lists, into a new mega-list. I'm currently doing ... |
thelist = [{'color':'green', 'time':4}, {'color':'red','time':2},{'color':'blue','time':5}]
How do I say:
If "red" is in thelist and time does not equal 2 for that element (that's we just got from the list):
|
So heres my code:
item = [0,1,2,3,4,5,6,7,8,9]
for item in z:
if item not in z:
print item
Z contains a list of integers. ... |
li = [0, 1, 2, 3]
running = True
while running:
for elem in li:
thiselem = elem
...
|
I'm looking for a "nice" way to process a list where some elements need to be expanded into more elements (only once, no expansion on the results).
Standard iterative way would be ... |
Given a list of numbers how to find differences between every (i)-th and (i+1)-th of its elements? Should one better use lambda or maybe lists comprehension?
Example:
Given a list t=[1,3,6,...] it is ... |
We have two lists:
a=['1','2','3','4']
b=['2','3','4','5']
How to get a list with elements that are contained in both lists:
a_and_b=['2','3','4']
and a list with elements that are contained only in one list, but not the other:
only_a=['1']
only_b=['5']
Yes, ... |
I need to do some special operation for the last element in a list.
Is there any better way than this?
array = [1,2,3,4,5]
for i, val in enumerate(array):
if (i+1) ... |
I'm looking for an equivalent in python of dictionary.get(key, default) for lists. Is there any one liner idiom to get the nth element of a list or a default value if ... |
I want count the same elements of two lists. Lists can have duplicate elements, so I can't convert this to sets and use & operator.
a=[2,2,1,1]
b=[1,1,3,3]
set(a) & set(b) work
a & b don't ... |
I have a list of arrays and I would like to get the cartesian product of the elements in the arrays.
I will use an example to make this more concrete...
itertools.product seems ... |
def do_work():
medications_subset2(b,['HYDROCODONE','MORPHINE','OXYCODONE'])
def medications_subset2(b,drugs_needed):
MORPHINE=['ASTRAMORPH','AVINZA','CONTIN','DURAMORPH','INFUMORPH',
'KADIAN','MS CONTIN','MSER','MSIR','ORAMORPH',
...
|
I have a list of numbers, say
data = [45,34,33,20,16,13,12,3]
I'd like to compute the difference between 2 and 2 items, (that is, for the above data
I want to compute 45-34,33-20,16-13 and 12-3, ... |
I need to build a list from a string in python using the [f(char) for char in string] syntax and I would like to be able to ignore (not insert in ... |
In [2]: list=range(627)
In [3]: list[::150]
Out[3]: [0, 150, 300, 450, 600]
the above code is right,but if i use the bellow code,caution:the l means long type,
the return result is not like above,what's the ... |
I'm new to Python, and i'm struggling to understand the output of this simple program:
list = os.listdir(os.getcwd())
print(list)
print()
for element in list:
print(element)
if 'txt' not in ...
|
I have been searching this for a while, basically I am trying to conditionally increment a list of element by another list, element-wise...
my code is following, but is there a better ... |
Let's say I have a Python list that looks like this:
list = [ a, b, c, d]
I am looking for the most efficient way performanse wise to get this:
list = [ ...
|
How do I assign incremental names in a list?
>>> ccList
['az <az@example.com>', 'cc777 <cc777@example.com>', 'user11 <user11@example.com>']
>>> for i in range(len(ccList)):
mailTuple = parseaddr(ccList[i])
cc = mailTuple[0]
...
|
Example:
numbers = ['1','2','3']
letters = ['a','b','c']
I want to get [1,a] as a results. Yeah I can loop through it, but I'm wondering if there is a fast one line way of doing ... |
Please help (I know that it's a silly question):
I have a list d = [' ABA', ' AAB', ' BAA', ' BAA', ' AAB', ' ABA']. How can I exclude elements ... |
Possible Duplicate:
Python - Differences between elements of a list
I have a list and I want to find difference between consecutive elements:
a = [0, 4, ...
|
I want to do something like this, but in python :
select * from [list] where [element at index n] = 'hello'
So far, I have this
cells = [' ...
|
Possible Duplicate:
Iterate over a python sequence in multiples of n?
How to list elements like: ['abcd', 'efghi'] ?
Using the next:
test = map(chr, range(97, 123))
for i ...
|
Ref:
python decompose a list
Flattening a shallow list in Python
While the above mentioned solutions are helpful, my problem is slightly different, and I was ... |
I am working with some xml files. The schema for the files specifies that there can only be one of a certain type of element (in this case I am ... |
I have three lists. Two are returned from functions. The other list, list_c, is being created in the program out of some hardcoded options and some variables, and the contents of ... |
I'm very new to python. I need a simple and clear script to add quotes to every list elements. Let me explain more. Here is the my code.
parameters = ['a', 'b', ...
|
I have a list
myList=[1,2,3,4]
I want to access '1' (i.e the first element of myList).
myList is an instance of class/type list & has its own datamembers/attributes [1,2,3,4]
so some way I must be ... |
import string
## This part of the code initializes the program by recieving inputs and saving
## them as strings.
## It also currently works!
intext = str.lower(raw_input("Please input the text you are going to ...
|
I have a list of indices, something like:
b=[0,2]
and a list of elements:
a = ['elem0','elem1','elem2']
I need a list that is composed of the elements in ... |
I have a list: test = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
Need to increase each list element in all possible ways using Python standard library. It's a ... |
Suppose I have a list [a,b,c,d,e], I want to create a list of tuples [(a,b,c),(b,c,d),(c,d,e)]. Is it possible without using array indices as my loop variable? What is the best way ... |
I Have a (very long) list, with this structure:
li1 = [[1.4, b][1.5, a][1.6, c][1,4, b][1.7,c][1.4, a][1.6,c]]
I want to write a loop that calculate amount of elements li1[i][0]` with identical value, ... |
|
dictionary = {"#":"guy", "nothing":"."} L = stan_pocz() #this is this list above for i in range (len(L)): for j in range (len(L)): if j == guy: ... |
|
>>> x = ['.py', '.pdf'] >>> y = ['1.py', '2.py', 'a.pdf', 'b.pdf'] >>> ext_dict = {k[1:]:[] for k in x} >>> ext_dict {'pdf': [], 'py': []} >>> for f in y: ... parts = f.rsplit('.',1) ... if len(parts) == 1: ... print "%s had no ... |
#! /usr/local/bin/python3 list = ['zero', 'one', 'two', 'three'] list = ['zero', 'one', 'two', 'three', 'four', 'five'] list = ['zero', 'one', 'two', 'three', 'C'] CRecordKey = 4 print ("list ............ ", list) print ("list[1] ......... ", list[1]) print ("list length ..... ", len(list)) if (len(list) > (CRecordKey)) : print("List item exists.") if (list[CRecordKey] == ... |
Dear All, I have got a list and a string, I want to check if the string starts with any of the elements in the list. I want to avoid map functions etc. I need it as a logival condition so I would like to have it investigated in one line. Is there any solution for this? Thanks |
I have a simple question; even though the method itself may not be efficient, and I would be open to alternate approaches, I think it would be instructive to have this matter clarified for me. Suppose you have a list, say, one with both numbers and strings as elements; or maybe it may work better to have strings with elements of ... |
|
I dont really know the index. In the change method user is asked to enter Name and Surname of the one to change. then I have a method to find who that is. It looks like this: Code: Select all def changeSearch(self,fnamn,enamn): tmp = [] ... |
for frame in range(1260, numberOfFrames+1): d = Interpolate(frame, distList) # returns a list [float, string] print d[1] # if I do this it gives me this error "TypeError: 'float' object is unsubscriptable" print d # this works, it prints ... |
>>> numList = [1,1,2,3,4,4,5,7,7,7,10] >>> for item in set(numList): ... print "Item: %s Duplicates: %s" % (item, numList.count(item)-1) ... Item: 1 Duplicates: 1 Item: 2 Duplicates: 0 Item: 3 Duplicates: 0 Item: 4 Duplicates: 1 Item: 5 Duplicates: 0 Item: 7 Duplicates: 2 Item: 10 Duplicates: 0 >>> |
|
|
Good Morning Guys. I am working on a program that will calculate the shannon diversity index from a user-specified number of ascii files that are created by a LiDAR software application my advisor wrote. I am new to python. The code below brings in the files, puts all the lines in each file into a list, and then parses each of ... |
def new_a(first): list_a = [first] for i in off_list: list_a.append(list_a[-1]+i) return list_a off_list = [2,2,2,2] first = 0 list_a = new_a(first) print list_a first = 7 list_a = new_a(first) print list_a # return values: >>> [0, 2, ... |
look, Im not looking for a solution, but since this is the beginners forum I'd expect something like... you're going to need to look into creating lists within dictionaries. I know how to make dictionaries and lists within dictionaries, but I have no idea how to define list elements that come after another. My idea (which doesnt work) goes something like ... |
|