Print function not working
I have installed IDLE 3.5.1 and wrote the following to check if print is working. When it runs, I do not see anything is printed: class Base: #{ def __init__( self ): #{ print("Hello, world: \n\n"); #} #} if ( __name__ == " __main__"): #{ root = Base(); #} Can anyone please point out the reason? Thanks, Atri -- https://mail.python.org/mailman/listinfo/python-list
Print function not working
I have installed IDLE 3.5.1 and wrote the following print command to see if it is working. When I ran the code nothing is printed. Can you please point the reason- anything wrong with the code? class Base: #{ def __init__( self ): #{ print("Hello, world: \n\n"); #} #} if ( __name__ == " __main__"): #{ root = Base(); #} Thanks, Atri -- https://mail.python.org/mailman/listinfo/python-list
Creating dictionary of items from Excel with mutliple keys
I am trying to create a following dictionary. I am reading data from excel which has data in the following format: Sl no: Name Thickness Length Material Width Quantity Side It has 20 rows of data. The dictionary for the 20 rows, I would like to make is Data_Dict = [ { 'Name': 'X', 'Length': '10' , 'Width': '5', 'Quantity': 2 'Area': 50}; { 'Name': 'Y', 'Length': '20' , 'Width': 10', 'Quantity': 1 'Area': 200}; . . . . till 20 rows ]; I would like to add another key 'Area' as shown above. I used the following code(s): using openpyxl: d={} for i in range(3,sheet.max_row+1): #for j in range(3,9): #for k in range(0,5): Name = sheet.cell(row= i,column=3).value Length =sheet.cell(row =i,column=6).value Breadth= sheet.cell(row=i,column=7).value Quantity = sheet.cell (row=i,column=8).value Area = sheet.cell(row =i,column=6).value*sheet.cell(row=i,column=7).value d[Name]= Length,Breadth,Quantity,Area which gave an output like: ['X': (10, 5, 2, 50), 'Y': (20, 10, 1, 2232600), 'Z': (5, 2, 1, 10), .] Another code using xlrd: keys = [sheet.cell(2, col_index).value for col_index in range(0,8)] print (keys) dict_list = [] d = {} for row_index in range(1, xl_sheet.nrows): for col_index in range(0,8): d = {keys[col_index]: xl_sheet.cell(row_index, col_index).value for col_index in range(0,8)} dict_list.append(d) print (dict_list) which did not have the area and neither the output was little messy. The main purpose is to sort the dictionary based on different criteria like Length or Area. I think the first one may be easier to sort. However if there are any better way to represent the dictionary and the code so that it can be sorted later based on different attributes please feel free to suggest. Thanks, Atri -- https://mail.python.org/mailman/listinfo/python-list
Finding the first index in a list greater than a particular value
I have a list of dictionaries which look like this: [{'Width': 100, 'Length': 20.0, 'Object': 'Object1'}, {'Width': 12.0, 'Length': 40.0, 'Object': 'Object2'}.. so on till 10] I would like to find the first index in the list of dictionaries whose length is greater than a particular value f=lambda seq, m: [ii for ii in range(0, len(seq)) if seq[ii]['Length'] > m][0] and it throws an error can anyone suggest a way to do it? Thanks, Atri -- https://mail.python.org/mailman/listinfo/python-list
Re: Finding the first index in a list greater than a particular value
On Monday, 15 August 2016 00:03:59 UTC+5:30, MRAB wrote: > On 2016-08-14 19:17, Atri Mahapatra wrote: > > I have a list of dictionaries which look like this: > > [{'Width': 100, 'Length': 20.0, 'Object': 'Object1'}, {'Width': 12.0, > > 'Length': 40.0, 'Object': 'Object2'}.. so on till 10] > > > > I would like to find the first index in the list of dictionaries whose > > length is greater than a particular value > > > > f=lambda seq, m: [ii for ii in range(0, len(seq)) if seq[ii]['Length'] > > > m][0] and it throws an error > > > > can anyone suggest a way to do it? > > > What is the error? Traceback (most recent call last): File "", line 1, in f(lengthlist, 10) f=lambda seq, m: [ii for ii in range(0, len(seq)) if seq[ii] > m][0] TypeError: unorderable types: dict() > int() -- https://mail.python.org/mailman/listinfo/python-list