xlrd spreadsheet to python list of dicts
I have a spreadsheet and Im using xlrd to parse to python.
I need to wrangle it (including the other sheets) into a list of dicts
like such:
[{"price4-0": 18.22, "price4-1": 21.23, "price4-4": 25.65, "quantity":
100.0, "turnaround": "1days", "size": "2 x 2"},
{"price4-0": 16.44, "price4-1": 19.43, "price4-4": 23.54, "quantity":
200.0, "turnaround": "1days", "size": "2 x 2"}...]
so 'turnaround' dict value is taken from the sheetname, and the other dict
keys are the first row value. I am trying to write it so if another sheet
or another row is added it will still work. Basically loop through and add
the right values in the right place. I have a hardcoded version which
gives correct result but it needs to be dynamic:
from pprint import pprint
import xlrd
wb = xlrd.open_workbook('cardprice.xls')
pricelist = []
for i, x in enumerate(wb.sheets()):
for r in range(x.nrows)[1:]:
row_values = x.row_values(r)
pricelist.append({'turnaround':x.name,
'size':row_values[0],
'quantity':row_values[1],
'price4-0':row_values[2],
'price4-1':row_values[3],
'price4-4':row_values[4]
})
pprint(pricelist)
Buchannon
Sunday, 1 September 2013
Textmate 2 Ruby Run settings for current directory
Textmate 2 Ruby Run settings for current directory
I have Ruby 2.0.0 and TextMate 2 playing along nicely, after some TM_RUBY
settings from http://hiltmon.com/blog/2013/01/16/rvm-in-textmate-2/.
However
I have
/Users/koos/Developments/RubyDevs/RubyTests/RubyLearn/Test1.rb and
/Users/koos/Developments/RubyDevs/RubyTests/RubyLearn/Test2.rb
Test1.rb has File.open("Test2.rb")
In TM 1.5 this worked, whether I open TM at the RubyDevs levels and drill
down, or if I open TM at the RubyLearn level.
In TM2 it gets "no such file or directory" if I open at RubyDevs level but
is ok if I open at RubyLearn level.
It is also OK if I change to
File.open("/Users/koos/Developments/RubyDevs/RubyTests/RubyLearn/Test2.rb")
This is clearly a settings issue of some sorts.
Any advise on this?
I have Ruby 2.0.0 and TextMate 2 playing along nicely, after some TM_RUBY
settings from http://hiltmon.com/blog/2013/01/16/rvm-in-textmate-2/.
However
I have
/Users/koos/Developments/RubyDevs/RubyTests/RubyLearn/Test1.rb and
/Users/koos/Developments/RubyDevs/RubyTests/RubyLearn/Test2.rb
Test1.rb has File.open("Test2.rb")
In TM 1.5 this worked, whether I open TM at the RubyDevs levels and drill
down, or if I open TM at the RubyLearn level.
In TM2 it gets "no such file or directory" if I open at RubyDevs level but
is ok if I open at RubyLearn level.
It is also OK if I change to
File.open("/Users/koos/Developments/RubyDevs/RubyTests/RubyLearn/Test2.rb")
This is clearly a settings issue of some sorts.
Any advise on this?
looping through List android
looping through List android
I have the following method:
public List<String> getAllValue(){
List<String> list = new ArrayList<String>();
if(pref.getString(KEY_NUMBER1 , "").length()>2)
list.add(pref.getString(KEY_NUMBER1 , ""));
if(pref.getString(KEY_NUMBER2 , "").length()>2)
list.add(pref.getString(KEY_NUMBER2 , ""));
if(pref.getString(KEY_NUMBER3 , "").length()>2)
list.add(pref.getString(KEY_NUMBER3 , ""));
if(pref.getString(KEY_NUMBER4 , "").length()>2)
list.add(pref.getString(KEY_NUMBER4 , ""));
if(pref.getString(KEY_NUMBER5 , "").length()>2)
list.add(pref.getString(KEY_NUMBER5 , ""));
return list;
}
What I need to do now is to assign these numbers(like KEY_NUMBER1) to the
following editTexts:
EditText phoneNumber1, phoneNumber2, phoneNumber3, phoneNumber4,
phoneNumber5;
Being new to working with Lists, I am having a hard time trying to figure
out a way to loop through and assign values to these editTexts, like
phoneNumber1.setText(KEY_NUMBER1);
phoneNumber2.setText(KEY_NUMBER2);
phoneNumber3.setText(KEY_NUMBER3);
I have the following method:
public List<String> getAllValue(){
List<String> list = new ArrayList<String>();
if(pref.getString(KEY_NUMBER1 , "").length()>2)
list.add(pref.getString(KEY_NUMBER1 , ""));
if(pref.getString(KEY_NUMBER2 , "").length()>2)
list.add(pref.getString(KEY_NUMBER2 , ""));
if(pref.getString(KEY_NUMBER3 , "").length()>2)
list.add(pref.getString(KEY_NUMBER3 , ""));
if(pref.getString(KEY_NUMBER4 , "").length()>2)
list.add(pref.getString(KEY_NUMBER4 , ""));
if(pref.getString(KEY_NUMBER5 , "").length()>2)
list.add(pref.getString(KEY_NUMBER5 , ""));
return list;
}
What I need to do now is to assign these numbers(like KEY_NUMBER1) to the
following editTexts:
EditText phoneNumber1, phoneNumber2, phoneNumber3, phoneNumber4,
phoneNumber5;
Being new to working with Lists, I am having a hard time trying to figure
out a way to loop through and assign values to these editTexts, like
phoneNumber1.setText(KEY_NUMBER1);
phoneNumber2.setText(KEY_NUMBER2);
phoneNumber3.setText(KEY_NUMBER3);
Saturday, 31 August 2013
How to change a character of an string into a different character?
How to change a character of an string into a different character?
I want to convert the space in a string into another character.
Ex:
var country = "United States"
I want the space to be "-" so:
var country = "Unites-States"
This is what I tried:
var country ="United States";
var countryArray = country.split(" ");
var newCountry = function(){
for(i=0;i<countryArray.length;i++){
if(countryArray[i]===","){
return countryArray[i]="-";}
}
I want to convert the space in a string into another character.
Ex:
var country = "United States"
I want the space to be "-" so:
var country = "Unites-States"
This is what I tried:
var country ="United States";
var countryArray = country.split(" ");
var newCountry = function(){
for(i=0;i<countryArray.length;i++){
if(countryArray[i]===","){
return countryArray[i]="-";}
}
What is proper way to create complex elements?
What is proper way to create complex elements?
What is the best way to create the following div element in jQuery?
<div class="btn-group">
<button class="btn dropdown-toggle" title="Manage" data-toggle="dropdown">
<span class="caret"></span>
</button>
</div>
I've tried multiple formats, but I can't seem to get it right.
var itemsButtonsDiv = $('<div><button><span></span></button></div>')
.addClass("btn-group")
.attr({
title: "Manage",
"data-toggle": "dropdown"
})
.find("button")
.addClass("btn dropdown-toggle")
.find("span")
.addClass("caret")
;
var itemsButtonsDiv = $("<div><button><span></span></button></div>", {
"class": "btn-group",
html: " ?? Does everything else go here as one long text string ?? "
});
I realize that I have to append the element separately after I create it,
but I can't get the creation right.
What is the best way to create the following div element in jQuery?
<div class="btn-group">
<button class="btn dropdown-toggle" title="Manage" data-toggle="dropdown">
<span class="caret"></span>
</button>
</div>
I've tried multiple formats, but I can't seem to get it right.
var itemsButtonsDiv = $('<div><button><span></span></button></div>')
.addClass("btn-group")
.attr({
title: "Manage",
"data-toggle": "dropdown"
})
.find("button")
.addClass("btn dropdown-toggle")
.find("span")
.addClass("caret")
;
var itemsButtonsDiv = $("<div><button><span></span></button></div>", {
"class": "btn-group",
html: " ?? Does everything else go here as one long text string ?? "
});
I realize that I have to append the element separately after I create it,
but I can't get the creation right.
Difficulty in understanding the approach for solving Spoj DQuery
Difficulty in understanding the approach for solving Spoj DQuery
I was trying to solve this problem on SPOJ:
http://www.spoj.com/problems/DQUERY/
But after a few hours of trying to solve it, I googled for a possible
hint. I found one approach described here:
http://apps.topcoder.com/forums/;jsessionid=5A69961AF7DF7FBB00FDFE13B80B5D2E?module=Thread&threadID=627423&start=0&mc=13
But I am not able to understand it properly. Can anybody help me in
understanding the approach.
I was trying to solve this problem on SPOJ:
http://www.spoj.com/problems/DQUERY/
But after a few hours of trying to solve it, I googled for a possible
hint. I found one approach described here:
http://apps.topcoder.com/forums/;jsessionid=5A69961AF7DF7FBB00FDFE13B80B5D2E?module=Thread&threadID=627423&start=0&mc=13
But I am not able to understand it properly. Can anybody help me in
understanding the approach.
DetailViewController programmatically iOS
DetailViewController programmatically iOS
Im using a custom ModalViewController called MZFormSheetController to
display a Detail View for UICollectionView. Currently I have created
properties in the modal view controller such as these :
@property (strong,nonatomic) NSString *user;
@property (strong,nonatomic) NSString *caption;
@property (weak, nonatomic) IBOutlet UILabel *username;
@property (weak, nonatomic) IBOutlet UILabel *captiontext;
And I attempt to set the display of the detail view controller when the
user taps on the UICollectionViewCell like this: -
(void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *entry = [self entries][indexPath.row];
NSDictionary *text = [self entries][indexPath.row];
ModalViewController *m = [self.storyboard
instantiateViewControllerWithIdentifier:@"modalView"];
m.entry = [self entries][indexPath.row];
m.text = [self entries][indexPath.row];
m.user = entry[@"user"][@"full_name"];
m.caption = text[@"caption"][@"text"];
MZFormSheetController *formSheet = [[MZFormSheetController alloc]
initWithViewController:m];
formSheet.transitionStyle = MZFormSheetTransitionStyleDropDown;
formSheet.shouldDismissOnBackgroundViewTap = YES;
[formSheet presentAnimated:YES completionHandler:^(UIViewController
*presentedFSViewController) {
}];
formSheet.didTapOnBackgroundViewCompletionHandler = ^(CGPoint location)
{
};
}
I have created two labels in storyboard for the modalviewcontroller and I
attempt to make them equal the caption and user values from the
MainViewController like this
[self.username.text isEqualToString:self.user];
[self.captiontext.text isEqualToString:self.caption];
However after all this the labels of the modal view controller still say
label like this..
Im using a custom ModalViewController called MZFormSheetController to
display a Detail View for UICollectionView. Currently I have created
properties in the modal view controller such as these :
@property (strong,nonatomic) NSString *user;
@property (strong,nonatomic) NSString *caption;
@property (weak, nonatomic) IBOutlet UILabel *username;
@property (weak, nonatomic) IBOutlet UILabel *captiontext;
And I attempt to set the display of the detail view controller when the
user taps on the UICollectionViewCell like this: -
(void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *entry = [self entries][indexPath.row];
NSDictionary *text = [self entries][indexPath.row];
ModalViewController *m = [self.storyboard
instantiateViewControllerWithIdentifier:@"modalView"];
m.entry = [self entries][indexPath.row];
m.text = [self entries][indexPath.row];
m.user = entry[@"user"][@"full_name"];
m.caption = text[@"caption"][@"text"];
MZFormSheetController *formSheet = [[MZFormSheetController alloc]
initWithViewController:m];
formSheet.transitionStyle = MZFormSheetTransitionStyleDropDown;
formSheet.shouldDismissOnBackgroundViewTap = YES;
[formSheet presentAnimated:YES completionHandler:^(UIViewController
*presentedFSViewController) {
}];
formSheet.didTapOnBackgroundViewCompletionHandler = ^(CGPoint location)
{
};
}
I have created two labels in storyboard for the modalviewcontroller and I
attempt to make them equal the caption and user values from the
MainViewController like this
[self.username.text isEqualToString:self.user];
[self.captiontext.text isEqualToString:self.caption];
However after all this the labels of the modal view controller still say
label like this..
Subscribe to:
Comments (Atom)