Posts

python 3.x - Accessing values in a dictionary -

here dictionary: {'request': [yearcount( year=2005, count=646179 ), yearcount( year=2006, count=677820 ), yearcount( year=2007, count=697645 ), yearcount( year=2008, count=795265 )], 'wandered': [yearcount( year=2005, count=83769 ), yearcount( year=2006, count=87688 ), yearcount( year=2007, count=108634 ), yearcount( year=2008, count=171015 )], 'airport': [yearcount( year=2007, count=175702 ), yearcount( year=2008, count=173294 )]} i need figuring out how access yearcount - count value. because i'm trying find letter frequency of each word such 'request', 'wandered', , 'airport'. count total number of each letter occurring in words in input data set. number divided total number of letters in words. if that's dictionary can access list of yearcount objects doing: objects = my_dict['request'] you can iterate on list , access .count values: for year_count in objects: print(year_count.count) ...

shell - LInux restore script returning unexpected token -

i creating recycle bin restore function linux. far have 1 script moves file recycle bin restore script not working. the purpose of restore script promt user directory move selected file recycle bin directory. when run script encounter error "unexpected token; fi" or whatever token try end file with. can see error in script? #!/bin/bash #changes directory location of recycle bin while read -r filename echo "where file restored to?" read newlocation mv -i ~/recycle/$filename $newlocation echo "file has been restored!" fi the syntax of while loop wrong. in bash while loops should this: while read -f filename ; # here goes loops body code done notice how added " ; " in loop head , how close loop "done" instead of "fi".

java - Spark Streaming App submit through code -

i trying submit spark streaming application through code sparkconf sparkconf= new sparkconf(); javastreamingcontext jssc = new javastreamingcontext(master, appname, new duration(60*1000), sparkhome, sparkjar); have given obsolute path dor sparkjar , sparkhome master spark://xyz:7077 i tried submitting batch processing in same way , worked not working streaming following error.. 14/11/26 17:42:25 info spark.httpfileserver: http file server directory /var/folders/3j/9hjkw0890sx_qg9yvzlvg64cf5626b/t/spark-cd7b30cd-cf95-4e52-8eb4-1c1dccc2d58f 14/11/26 17:42:25 info spark.httpserver: starting http server 14/11/26 17:42:25 info server.server: jetty-8.1.14.v20131031 14/11/26 17:42:25 info server.abstractconnector: started socketconnector@0.0.0.0:50016 14/11/26 17:42:25 info server.server: jetty-8.1.14.v20131031 14/11/26 17:42:25 info server.abstractconnector: started selectchannelconnector@0.0.0.0:4040 14/11/26 17:42:25 info ui.sparkui: started sparkui @ http://xxx.xx.xxx.xx:4040 ...

c++ - Do Vectors resize automatically? -

i sorry asking such beginner question finding contradictory information online. ask @ university out until february next year. do vectors resize automatically? or need check current size periodically , resize when need more room. looks resizing me automatically i'm not sure if feature or compiler waving magic wand. if use push_back or insert , yes vector resizes itself. here demo: #include<iostream> #include<vector> using namespace std; int main() { vector < int > a; a.push_back(1); a.push_back(2); a.push_back(3); (int value : a) { cout << value << " "; } cout << endl << "current size " << a.size() << endl; return 0; } it gives output as: 1 2 3 current size 3 remember if a[3] = 5 . not resize vector automatically. can manually resize vector if want. demo append following code above code. a.resize(6); (int value : a) { cout << ...

java - Coordinate Issues with ImageButtons -

i programming android app/game allows users purchase buildings drag , drop imagebuttons (implementing drag , drop api). when user drags buildings around, coordinates stored in sqlite database when dropped. say user buys 2 buildings: first colonyhut , second homehut. user places 2 buildings wherever wish, coordinates of buildings saved. issue when app closed , opened again. whenever app loads up, wherever second building (homehut) left first building (colonyhut) be. i have been fighting issue forever , not why first building continually take coordinates of second building when second building moved. here code check see if these 2 buildings have been purchased previously. if have dynamically created , inserted view. newhomehutoneid = prefs.getint("newhomehutone", 0); if (newhomehutoneid != 0) { data.open(); homehutonex = data.gethomehutonex(); homehutoney = data.gethomehutoney(); data.close(); newhomehutframe = (fr...

sap - How to transpose an internal table rows into columns? -

i want transpose internal table rows column , want fix first column,i trying following code not getting expected result....it not converting rows columns *types declaration types: begin of ty_t001w, ekorg type t001w-ekorg, werks type t001w-werks, name1 type t001w-name1, end of ty_t001w. **field symbols declaration field-symbols: <fs1> type any, <fs2> type any. **internal table , work area declaration data: it1_col_row type standard table of ty_t001w, wa1_col_row type ty_t001w, it2_col_row type standard table of ty_t001w, wa2_col_row type ty_t001w, cline type sy-tabix. **filling internal table data select * t001w corresponding fields of table it1_col_row ekorg = p_ekorg , fabkl = p_fabkl. **looping internal table display data loop @ it1_col_row wa1_col_row. write: / wa1_col_row-ekorg, wa1_col_row-werks,wa1_col_row-name1. endloop. write: /. **looping internal table chan...

php - Running functions on form data before/during validation in Yii 2 -

ok, example if entering username , want make lowercase before or @ beginning of validation (in rules method) how can this? i know can similar trim such as: [['company_name', 'first_name', 'last_name', 'email', 'username', 'password', 'password2'], 'trim'] but assume doesn't support function? so, want run strtolower function on username, way go doing this? need use beforevalidate method or can this? ['username', 'makelower'] public function makelower($attribute, $params) { $this->$attribute = strtolower($this->$attribute); } you can use filtervalidator . ['username', 'filter', 'filter' => 'strtolower'] filtervalidator not validator data processor. invokes specified filter callback process attribute value , save processed value attribute. filter must valid php callback following signature: function foo($...