I have written a simple python program
l=[1,2,3,0,0,1]
for i in range(0,len(l)):
if l[i]==0:
l.pop(i)
This gives ... |
Why is print(x) here not valid (SyntaxError) in the following list-comprehension?
my_list=[1,2,3]
[print(my_item) for my_item in my_list]
To contrast - the following doesn't give a syntax error:
def my_func(x):
print(x)
[my_func(my_item) for my_item ...
|
I've got a list comprehensions which filter a list:
l = [obj for obj in objlist if not obj.mycond()]
but the object method mycond() can raise an Exception I must intercept. I need ... |
B=l.append((l[i]+A+B))
l is a list here and i am trying to append into it more value for it to act as an array . But its still giving me error like list ... |
A=s.append(s[i]+A+B)
A=s.append(s[i]+A+B)
TypeError: unsupported operand type(s) for +: 'long' and 'str'
What does this error mean ? A and B are strings and s is a list
|
I am working on a python tetris game that my proffessor assigned for the final project of a concepts of programming class. I have got just about everything he wanted to ... |
from string import Template
from string import Formatter
import pickle
f=open("C:/begpython/text2.txt",'r')
p='C:/begpython/text2.txt'
f1=open("C:/begpython/text3.txt",'w')
m=[]
i=0
k='a'
while k is not '':
k=f.readline()
mi=k.split(' ')
m=m+[mi]
i=i+1
print m[1]
f1.write(str(m[3]))
f1.write(str(m[4]))
x=[]
j=0
while ...
|
|
closed = set() -here closed is a set
node is (5,5)
The error occurse at execution time.
Error is:
list objects are unhashable
the program is:
closed.add(node)
for val in closed:
...
|
hey guys, beginner here. I have written a program that outputs files to .txt's and am using another to read them and use them. i have used a list to store ... |
Ok, so I'm writing some python code (I don't write python much, I'm more used to java and C).
Anyway, so I have collection of integer literals I need to store.
(Ideally >10,000 ... |
There is a list standard python exceptions that we should watch out, but I don't think these are the ones we should raise ourselves, cause they are rarely applicable.
I'm ... |
I was writing a simple genetic program to test out the process, but got the following error:
Traceback (most recent call last):
File "evolution.py", line 43, in <module>
...
|
Why on earth Python lets change not global declared list in function?
RE-UPDATED
numbers = []
num = 4
def add(n, thisnum=None):
# changing global list without global declaration!
...
|
Basically it's supposed to take a set of coordinates and return a list of coordinates of it's neighbors. However, when it hits here:if result[i][0] < 0 or result[i][0] >= board.dimensions:
... |
I want to use pep8 as my makeprg in order to check and fix my code compliance to PEP8 (Style guide for python code).
I used the command :set makeprg=pep8\ ... |
I'm new to Python. I'm writing a simple class but I'm with an error.
My class:
import config # Ficheiro de configuracao
import twitter
import random
import sqlite3
import time
import bitly_api #https://github.com/bitly/bitly-api-python
class TwitterC:
...
|
python version: 2.71
I get a syntax error whenever I try to run it with IDLE....
horsemen = ["war", "famine", "pestilence", "death"]
i = 0
while i < 4:
print horsemen[i]
...
|
this is my code :
a=[1,0,None,3]
def b(my_list):
for i in range(len(my_list)):
if not my_list[i]:
...
|
def main():
L=[]
list1=[5,1,3]
list2=[4,6,2]
L.append(list1)
L.append(list2)
f(L)
def f(L):
for ...
|
I've code this code in Python:
if type(data).__name__=='list':
print type(data).__name__
...
|
If I alter a variable declared at the top of the file/module from within a method (no classes involved), it only works in the case of lists/containers, but not if my ... |
I've written a simple Python program to send automated emails through Exchange. Everything seems to be going fine on my end; the conversation with the Exchange server goes as follows:
send: 'ehlo ...
|
I am writing an algorithm to represent regression trees, using pydot module (an interface to Graphviz's Dot language).
In the algorithm, lists of Edges and Nodes are made, and then they are ... |
I'm trying to build a markov generator that takes an arbitrary length for the chain of words as a programming exercise, but I've found a bug I just can't quite seem ... |
I am making a simple Checkers again. And, in order to keep track of all the locations for the checkers to move to, I created a list to add all of ... |
Possible Duplicate:
Removing from a list while iterating over it
I have this code:
s = [2,3,4,5]
for i in s:
s.remove(i)
print(s)
When I run it, the ... |
I am sorry to post a long code. I have extracted the parts of my code where the list lower_lip_under_upper_list_plist is generated and used. There is an error of linking the ... |
|
"i want to loop through the list" is the same thing as traversing a list which I covered in my first post, as well as a link on how to search the record using the in operator. If you are not going to read the posts then there is no reason to post further. |
|
I am writing a script to take my MP3 that are above 192kbs bitrate and downmix them to 192kbs. If they are less than 192kbs I want it to ignore them. I will be using pacpl as my converting backend. I am very new to python and high level languages entirely. I am writing the code to get a directory listing ... |
import os import sys if __name__ == '__main__': from wlstModule import *#@UnusedWildImport #======================================================================================= # Open a domain template. #======================================================================================= beaHome=os.environ["BEA_HOME"] wlHome=os.environ["WL_HOME"] print "beaHome="+beaHome print "wlHome="+wlHome print "Domain Name:"+sys.argv[1] print "Domian port:"+sys.argv[2] print "Domain ssl:"+sys.argv[3] print "Weblogic Username:"+sys.argv[4] print "Weblogic Password:"+sys.argv[5] readTemplate(wlHome + "/common/templates/domains/wls.jar") cd('Servers/AdminServer') set('ListenAddress','') set('ListenPort',sys.argv[1]) create('AdminServer','SSL') cd('SSL/AdminServer') set('Enabled', 'True') set('ListenPort', 8002) #======================================================================================= # Define the user password for weblogic. #======================================================================================= ... |
Hi, I am creating a new weblogic domain through the python script. i am passing the arugment list to the port number, but i am getting error.. Below is my script. ##################################################################### import os import sys if __name__ == '__main__': from wlstModule import *#@UnusedWildImport #======================================================================================= # Open a domain template. #======================================================================================= beaHome=os.environ["BEA_HOME"] wlHome=os.environ["WL_HOME"] print "beaHome="+beaHome print "wlHome="+wlHome print "Domain Name:"+sys.argv[1] print ... |
My code is as follows: def TA2SA(TA): x = [0,0,0] y=TA[0]+TA[1]+TA[2]+2 n = int(math.log(y / 2) / math.log(2)) #Compute the n value on the basis that the ternary sum equals 2**(n-1)+2 SA = [0] * n #Initiate a SA list of length n. for i in range(3): #Initiate vector x to store bit representation of ternary address. x[i] = [0] * ... |
def foo(file_name): with open(file_name, 'r') as ifh: lines = ifh.readlines() for line in lines: pieces = line.strip().split('\t') if len(pieces) < 3: ... |
|
|
Hello, allow me to introduce myself, I tend to call myself Kit for some reason. I'm somewhat new to Linux, running Arch on a 1005HA eeepc as largely an experiment I'm liking very much. I'm new to python, slowly teaching myself and thus far it's gone well until I've tried to code up a dice program. My code follows, as well ... |
39. list error python-forum.org |
list index error plz help by andrew3000 Sun Nov 15, 2009 1:04 pm Hi i have the following code: Code: Select all # -*- coding: utf-8 -*- #Aktiekp from Tkinter import * class Aktie(object): def __init__(self, aktie, datum, varde, hVarde, lVarde, kursutveckling, betavarde): ... |
Okay. I'm putting numbers into a list. A lot of numbers. While debugging len(GCs) gives me 4000. So that tells me that the list has 4000 values, right. Anyway, heres the code: for i in range(len(GCs[0])): suma = 0 print len(GCs) for j in range(len(GCs)): print j suma += GCs[j][i] GCAV.append(suma/len(GCs)) printing is in there to debug. So I get len(GCs) ... |
fp = open('classify') for line in fp: a = line.split() print a # This will print the whole list for debugging purposes print a[2] # If the program crashes here you will be able to see 'a' from the line above ... |
43. List Error python-forum.orgdata = ['a', 'b', 'c'] print data[10] --output:-- print data[10] IndexError: list index out of range data = [] print data[10] --output:-- print data[10] IndexError: list index out of range data = [] print data[0] --output:-- print data[0] IndexError: list index out of range data = [] data[0] = "hello" --output:-- data[0] = "hello" IndexError: list assignment index out of range ... |