my L1 array contains numbers like 0.029999999999999999 which i want to print off as 0.03
my code works, but gives an error at the end because the last count is out of ... |
Say I have a function func(i) that creates an object for an integer i, and N is some nonnegative integer. Then what's the fastest way to create a list (not a ... |
I'm building a range between two numbers (floats) and I'd like this range to be of an exact fixed length (no more, no less). range and arange work with steps, ... |
a=['123','2',4]
b=a[4] or 'sss'
print b
I want to get a default value when the list index is out of range (here: 'sss').
How can I do this?
|
Below I have the following code that is supposed to get the CPU temperature.
import wmi
w = wmi.WMI()
print w.Win32_TemperatureProbe()[0].CurrentReading
When I run it I get the following warning however:
Traceback (most recent call ...
|
I tagged this question with poisson as I am not sure if it will be helpful in this case.
I need to create a distribution (probably formatted as an image in the ... |
I have
def findfreq(nltktext, atitem)
fdistscan = FreqDist(nltktext)
distlist = fdistscan.keys()
return distlist[:atitem]
which relies on FreqDist from the NLTK package, and does not ... |
|
From a list mylist = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] how can I get a new list of lists composed of the first two elements of each ... |
imagine that i have a list like l=[[10,50,90],[70,80,90],[88,90,55]]
10 50 90
70 80 40
88 90 55
I sum an item with the others around it(so the sum of ... |
I have problem with the netaddr package - version 0.7.5. This code works as expected and prints out the list of ip addresses in the range:
from netaddr import IPNetwork
ipnetwork = '192.168.0.0/24'
print ...
|
how is this possible, I have a list called "temp". This is what I have in my python interpreter.
In [150]: len(temp)
Out[150]: 773942
In [151]: temp[773942]
and I get an IndexError: list index ... |
Hey, I am trying to build a set of ranges in python like so:
Given (0.1, 0.2, 0.7)
I want to build [(0, 0.1), (0.1, 0.3), (0.3, 1)]
While this could be achieved easily ... |
import glob
import xlrd
from xlwt import Workbook
wb = Workbook()
for file_name in glob.glob("foo*.xls"):
wb_orig = xlrd.open_workbook(file_name)
for ws_orig in wb_orig.sheets():
...
|
I know this is wrong thing to do, but I am using python 3 but studying it with python 2 book.
it says,
>>>range(2,7)
will show
[2,3,4,5,6]
but I know it won't show the output ... |
def remove_section(alist, start, end):
"""
Return a copy of alist removing the section from start to end inclusive
>>> inlist = [8,7,6,5,4,3,2,1]
...
|
I have written a program that makes sure each cookie has more than 5 chips before moving on.
However, the line if cookie[i] > 5: seems to be problematic, as it produces ... |
I am studying the Learn Python The Hard Way PDF. On page 82 i come across this question.
- Could you have avoided that for-loop entirely on line 23 and just ...
|
This first lines work, and i get V(i) =V+QIN(i)-QOUT(i), but when i try to do
T(i) = (T + C(i) + TIN(i)*QIN(i)) /((C(i)+QIN(i)), how can I loop trought each C ... |
What is a pythonic way of making list of arbitrary length containing evenly spaced numbers (not just whole integers) between given bounds? For instance:
my_func(0,5,10) # ( lower_bound , upper_bound , length ...
|
here is a list lst = [5, 3, 5, 1, 4, 7]
I want to get it ordered from the second element 3 to the end.
I thought I can do it by: ... |
#!/usr/bin/python
import os,sys
from os import path
input = open('/home/XXXXXX/ERR001268_1', 'r').read().split('\n')
at = 1
for lines in range(0, len(input)):
line1 = input[lines]
line4 = input[lines+3]
num1 = ...
|
I am new to Python and am getting the list index error, when I shouldn't.
I have the following variable:
date_array = ['2001','15','1']
I can access the first index. I can only access ... |
I have the following code:
def steps(low, hi, n):
rn = range(n)
newrn = rn
print rn #print 1
for x in rn[:]:
print x
newrn[x] = float(x)/n
diff = ...
|
|
|
Hey guys, This probly a really easy fix. I know this exception occurs when you try and access an index which does not exist, but this code worked fine then just started giving this error and i cant figure out why... cur.execute('select first, last from users where email = ?', [email]) userlist = [] for user in cur.fetchall(): userlist.append( (user[0] + ... |
Re: getting ranges between lists? by gundliwe Fri Oct 28, 2011 10:20 am I get the error Traceback (most recent call last): File "Blocks.py", line 25, in Exon = set(blockrange) TypeError: unhashable type: 'list' Code: Select all #! /usr/bin/env python # Open the two files import sys import fileinput # Open the two files f1 = open(sys.argv[1], "r") f2_recs ... |
List index out of Range HELP! by GeorgeM Thu Feb 17, 2011 4:40 am I'm a begginer and literally know none of the Python mumbojumbo. So basically I'm asking for someone to simply explain it is simple english or fixe it for me You'll see the problem if you run the program...thanks for your help!!! Here's my code: # gui.py ... |
Code: Select all def coordinate_gen(width,length): coordinates=[] c_count=0 w_count=0 l_count=1 letters=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] width_list=[] length_list=[] for i in range(length): ... |
Hi I have the following 2 lists l1 = [12, 34, 55... etc] l2 = [14, 56, 41...etc] they are the same length, but i want to know how to get the ranges of the corresponding numbers in each list and put that into a new list. So basically i want the range of 12 and 14, 34 and 56, so ... |
def normList(L, normalizeToUp=1.4, normalizeToDown=-2.3): vMax = float(max(L)) vMin = float(min(L)) r = vMax-vMin nr = float(normalizeToUp - normalizeToDown) lNorm = [ normalizeToDown + (x/r)*nr for x in L] return lNorm |
column_height = 10 candidate = [] for i in xrange(0, column_height - 2): for j in matrix[i]: num = 1 for k in xrange(0, 3): num *= matrix[i+k][j] ... |
Hello. How do I include a list of numbers into a range function? For example, if I have a list: list1 = [1,2,3] how do I use the range function so that it will use the numbers from the list? I tried this : list1 = [1,2,3] >>>for i in range(list1): >>>print i and some variations of it but it doesn't ... |
Here's the code: Code: Select all class Employee: def __init__(self, name, age, gender, salary): self.name = name self.age = age self.gender = gender self.salary = salary def ... |
data = ['0','one','two','three','four','five','six','7','8','9','10','1','3','11','12','14'] for i in data: if i[0] == '0': print i[1] Traceback (most recent call last): File "C:\scripts\Python-1.py", line 15, in print i[1] IndexError: string index out of range |
|
|