Search Results

Search found 163 results on 7 pages for 'banana'.

Page 3/7 | < Previous Page | 1 2 3 4 5 6 7  | Next Page >

  • Switch two items in associative array PHP

    - by user280381
    Example: $arr = array('apple'='sweet','grapefruit'='bitter','pear'='tasty','banana'='yellow'); I want to switch the positions of grapefruit and pear, so the array will become 'apple'='sweet','pear'='tasty','grapefruit'='bitter','banana'='yellow') I know the keys and values of the elements I want to switch, is there an easy way to do this? Or will it require a loop + creating a new array? Thanks

    Read the article

  • Letter Count on a string

    - by user74283
    Python newb here. I m trying to count the number of letter "a"s in a given string. Code is below. It keeps returning 1 instead 3 in string "banana". Any input appreciated. def count_letters(word, char): count = 0 while count <= len(word): for char in word: if char == word[count]: count += 1 return count print count_letters('banana','a')

    Read the article

  • What Mysql query will return this result?

    - by Lost_in_code
    I have two tables A,B which are related to each other (simplified): A: +-------+---------+ | id | type | +-------+---------+ | 1 | apple | | 2 | orange | | 3 | banana | +-------+---------+ B: +-------+---------+-----------+ | id | a_id | rank | +-------+---------+-----------+ | 1 | 1 | 0.0 | | 2 | 1 | 7.7 | | 3 | 2 | 3.3 | | 4 | 2 | 8.8 | | 5 | 2 | 1.1 | | 6 | 3 | 3.3 | | 7 | 3 | 5.5 | | 8 | 1 | 9.5 | +-------+---------+-----------+ What mysql query will return the following result? Result +-------+---------+-----------+ | id | type | rank | +-------+---------+-----------+ | 1 | apple | 9.5 | | 2 | orange | 1.1 | | 3 | banana | 5.5 | +-------+---------+-----------+

    Read the article

  • java: <identifier> expected with ArrayList

    - by A-moc
    I have a class named Storage. Storage contains an arraylist of special objects called Products. Each product contains information such as name, price, etc. My code is as follows: class Storage{ Product sprite = new Product("sprite",1.25,30); Product pepsi = new Product("pepsi",1.85,45); Product orange = new Product("orange",2.25,36); Product hershey = new Product("hershey",1.50,33); Product brownie = new Product("brownie",2.30,41); Product apple = new Product("apple",2.00,15); Product crackers = new Product("peanut",3.90,68); Product trailmix = new Product("trailmix",1.90,45); Product icecream = new Product("icecream",1.65,28); Product doughnut = new Product("doughnut",2.75,18); Product banana = new Product("banana",1.25,32); Product coffee = new Product("coffee",1.30,40); Product chips = new Product("chips",1.70,35); ArrayList<Product> arl = new ArrayList<Product>(); //add initial elements to arraylist arl.add(sprite); arl.add(pepsi); arl.add(orange); arl.add(hershey); arl.add(brownie); arl.add(apple); arl.add(peanut); arl.add(trailmix); arl.add(icecream); arl.add(doughnut); arl.add(banana); arl.add(coffee); arl.add(chips); } Whenever I compile, I get an error message on lines 141-153 stating <identifier> expected. I know it's an elementary problem, but I can't seem to figure this out. Any help is much appreciated.

    Read the article

  • Preserving hierarchy when converting .csv file to xml or json

    - by Simon Levinson
    Hello I have a question concerning translating data from a CSV into XML or JSON where it is essential to preserve the heirarchy of the data. For example, if I have CSV data like this: type,brand,country,quantity apple,golden_delicious,english,1 apple,golden_delicious,french,2 apple,cox,,4 apple,braeburn,,1 banana,,carribean,6 banana,,central_america,7 clememtine,,,3 What I want is to preserve hierarchy in the XML so that I get something like: <fruit> <type = "apple"> <brand = "golden_delicious"> <country = "english" quantity = "1"> <country = "french" quantity = "2"> </brand> <brand = "cox"> <quantity = "4"> </brand> <brand = "braeburn"> <quantity = "1"> </brand> </type> <type = "banana"> <country = "carribean" quantity = "6"> <country = "central_america" quantity = "7"> </type> <type = "clementine"> <quantity = "3"> </type> <fruit /> Is it best to try to use JAXP or to convert the above into a table simply of parent, child and then writing the data to an array of strings for processing,? Like this: parent,child fruit,apple apple,golden_delicious golden_delicious,english golden_delicious,french english,1 french,2 apple,cox cox,4 apple,braeburn braeburn,1 And so on. Or is there a better way? Thanks Simon Levinson

    Read the article

  • SQL View with Data from two tables

    - by Alex
    Hello! I can't seem to crack this - I have two tables (Persons and Companies), and I'm trying to create a view that: 1) shows all persons 2) also returns companies by themselves once, regardless of how many persons are related to it 3) orders by name across both tables To clarify, some sample data: (Table: Companies) Id Name 1 Banana 2 ABC Inc. 3 Microsoft 4 Bigwig (Table: Persons) Id Name RelatedCompanyId 1 Joe Smith 3 2 Justin 3 Paul Rudd 4 4 Anjolie 5 Dustin 4 The output I'm looking for is something like this: Name PersonName CompanyName RelatedCompanyId ABC Inc. NULL ABC Inc. NULL Anjolie Anjolie NULL NULL Banana NULL Banana NULL Bigwig NULL Bigwig NULL Dustin Dustin Bigwig 4 Joe Smith Joe Smith Microsoft 3 Justin Justin NULL NULL Microsoft NULL Microsoft NULL Paul Rudd Paul Rudd Bigwig 4 As you can see, the new "Name" column is ordered across both tables (the company names appear correctly in between the person names), and each company appears exactly once, regardless of how many people are related to it. Can this even be done in SQL?! P.S. I'm trying to create a view so I can use this later for easy data retrieval, fulltext indexing and make the programming side simpler by just querying the view.

    Read the article

  • how to match var/id to class

    - by circey
    Hi. I'm new to jquery and, in addition, I think I'm having a brain freeze. I have a number of links with different ids. I want to match the clicked link with a div with the corresponding class so the div will show/hide/toggle as appropriate. I have: <script type="text/javascript"> $(document).ready(function() { $('.folioBox').hide(); $('a.interface').click(function(){ var currentId = $(this).attr('id'); var currentBox = $('.folioBox .' + currentId); $(currentBox).toggle(400); }); }); </script> <a class="interface" id="apple">Apple flavor</a> <a class="interface" id="banana">Banana flavor</a> <a class="interface" id="cherry">Cherry flavor</a> <div class="folioBox apple">content</div> <div class="folioBox banana">content</div> <div class="folioBox cherry">content</div> I just can't get it to work and I can't figure out whether I would be best using match or find or filter. Some assistance would be much appreciated!

    Read the article

  • django class with an array of "parent" foreignkeys issue

    - by user298032
    Let's say I have a class called Fruit with child classes of the different kinds of Fruit with their own specific attributes, and I want to collect them in a FruitBasket: class Fruit(models.Model):     type = models.CharField(max_length=120,default='banana',choices=FRUIT_TYPES)     ... class Banana(Fruit):     """banana (fruit type)"""     length = models.IntegerField(blank=True, null=True)     ... class Orange(Fruit):     """orange (fruit type)"""     diameter = models.IntegerField(blank=True, null=True)     ... class FruitBasket(models.Model):     fruits = models.ManyToManyField(Fruit)     ... The problem I seem to be having is when I retrieve and inspect the Fruits in a FruitBasket, I only retrieve the Fruit base class and can't get at the Fruit child class attributes. I think I understand what is happening--when the array is retrieved from the database, the only fields that are retrieved are the Fruit base class fields. But is there some way to get the child class attributes as well without multiple expensive database transactions? (For example, I could get the array, then retrieve the child Fruit classes by the id of each array element). thanks in advance, Chuck

    Read the article

  • PHP - Tricky... array into columns, but in a specific order.

    - by Joe
    <?php $combinedArray = array("apple","banana","watermelon","lemon","orange","mango"); $num_cols = 3; $i = 0; foreach ($combinedArray as $r ){ /*** use modulo to check if the row should end ***/ echo $i++%$num_cols==0 ? '<div style="clear:both;"></div>' : ''; /*** output the array item ***/ ?> <div style="float:left; width:33%;"> <?php echo $r; ?> </div> <?php } ?> <div style="clear:both;"></div> The above code will print out the array like this: apple --- banana --- watermelon lemon --- orange --- mango However, I need it like this: apple --- watermelon --- orange banana --- lemon --- mango Do you know how to convert this? Basically, each value in the array needs to be placed underneath the one above, but it must be based on this same structure of 3 columns, and also an equal amount of fruits per column/row (unless there was like 7 fruits there would be 3 in one column and 2 in the other columns. Sorry I know it's confusing lol

    Read the article

  • shielding #include within namespace { } block?

    - by Jeff
    Edit: I know that method 1 is essentially invalid and will probably use method 2, but I'm looking for the best hack or a better solution to mitigate rampant, mutable namespace proliferation. I have multiple class or method definitions in one namespace that have different dependencies, and would like to use the fewest namespace blocks or explicit scopings possible but while grouping #include directives with the definitions that require them as best as possible. I've never seen any indication that any preprocessor could be told to exclude namespace {} scoping from #include contents, but I'm here to ask if something similar to this is possible: (see bottom for explanation of why I want something dead simple) // NOTE: apple.h, etc., contents are *NOT* intended to be in namespace Foo! // would prefer something most this: namespace Foo { #include "apple.h" B *A::blah(B const *x) { /* ... */ } #include "banana.h" int B::whatever(C const &var) { /* ... */ } #include "blueberry.h" void B::something() { /* ... */ } } // namespace Foo ... // over this: #include "apple.h" #include "banana.h" #include "blueberry.h" namespace Foo { B *A::blah(B const *x) { /* ... */ } int B::whatever(C const &var) { /* ... */ } void B::something() { /* ... */ } } // namespace Foo ... // or over this: #include "apple.h" namespace Foo { B *A::blah(B const *x) { /* ... */ } } // namespace Foo #include "banana.h" namespace Foo { int B::whatever(C const &var) { /* ... */ } } // namespace Foo #include "blueberry.h" namespace Foo { void B::something() { /* ... */ } } // namespace Foo My real problem is that I have projects where a module may need to be branched but have coexisting components from the branches in the same program. I have classes like FooA, etc., that I've called Foo::A in the hopes being able to branch less painfully as Foo::v1_2::A, where some program may need both a Foo::A and a Foo::v1_2::A. I'd like "Foo" or "Foo::v1_2" to show up only really once per file, as a single namespace block, if possible. Moreover, I tend to prefer to locate blocks of #include directives immediately above the first definition in the file that requires them. What's my best choice, or alternatively, what should I be doing instead of hijacking the namespaces?

    Read the article

  • alternative to #include within namespace { } block

    - by Jeff
    Edit: I know that method 1 is essentially invalid and will probably use method 2, but I'm looking for the best hack or a better solution to mitigate rampant, mutable namespace proliferation. I have multiple class or method definitions in one namespace that have different dependencies, and would like to use the fewest namespace blocks or explicit scopings possible but while grouping #include directives with the definitions that require them as best as possible. I've never seen any indication that any preprocessor could be told to exclude namespace {} scoping from #include contents, but I'm here to ask if something similar to this is possible: (see bottom for explanation of why I want something dead simple) // NOTE: apple.h, etc., contents are *NOT* intended to be in namespace Foo! // would prefer something most this: namespace Foo { #include "apple.h" B *A::blah(B const *x) { /* ... */ } #include "banana.h" int B::whatever(C const &var) { /* ... */ } #include "blueberry.h" void B::something() { /* ... */ } } // namespace Foo ... // over this: #include "apple.h" #include "banana.h" #include "blueberry.h" namespace Foo { B *A::blah(B const *x) { /* ... */ } int B::whatever(C const &var) { /* ... */ } void B::something() { /* ... */ } } // namespace Foo ... // or over this: #include "apple.h" namespace Foo { B *A::blah(B const *x) { /* ... */ } } // namespace Foo #include "banana.h" namespace Foo { int B::whatever(C const &var) { /* ... */ } } // namespace Foo #include "blueberry.h" namespace Foo { void B::something() { /* ... */ } } // namespace Foo My real problem is that I have projects where a module may need to be branched but have coexisting components from the branches in the same program. I have classes like FooA, etc., that I've called Foo::A in the hopes being able to branch less painfully as Foo::v1_2::A, where some program may need both a Foo::A and a Foo::v1_2::A. I'd like "Foo" or "Foo::v1_2" to show up only really once per file, as a single namespace block, if possible. Moreover, I tend to prefer to locate blocks of #include directives immediately above the first definition in the file that requires them. What's my best choice, or alternatively, what should I be doing instead of hijacking the namespaces?

    Read the article

  • mysql select update

    - by Tillebeck
    Hi I have read quite a few selcet+update questions in here but cannot understand how to do it. So will have to ask from the beginning. I would like to update a table based on data in another table. Setup is like this: - TABLE a ( int ; string ) ID WORD 1 banana 2 orange 3 apple - TABLE b ( "comma separated" string ; string ) WORDS TEXTAREA 0 banana -> 0,1 0 orange apple apple -> BEST:0,2,3 ELSE 0,2,3,3 0 banana orange apple -> 0,1,2,3 Now I would like to for each word in TABLE a append ",a.ID" to b.WORDS like: SELECT id, word FROM a (for each) -> UPDATE b SET words = CONCAT(words, ',', a.id) WHERE b.textarea like %a.word% Or even better: replace the word found in b.textarea with ",a.id" so it is the b.textarea that ends up beeing a comma separeted string of id's... But I do not know if that is possible.

    Read the article

  • Skip subdirectory in python import

    - by jstaab
    Ok, so I'm trying to change this: app/ - lib.py - models.py - blah.py Into this: app/ - __init__.py - lib.py - models/ - __init__.py - user.py - account.py - banana.py - blah.py And still be able to import my models using from app.models import User rather than having to change it to from app.models.user import User all over the place. Basically, I want everything to treat the package as a single module, but be able to navigate the code in separate files for development ease. The reason I can't do something like add for file in __all__: from file import * into init.py is I have circular references between the model files. A fix I don't want is to import those models from within the functions that use them. But that's super ugly. Let me give you an example: user.py ... from app.models import Banana ... banana.py ... from app.models import User ... I wrote a quick pre-processing script that grabs all the files, re-writes them to put imports at the top, and puts it into models.py, but that's hardly an improvement, since now my stack traces don't show the line number I actually need to change. Any ideas? I always though init was probably magical but now that I dig into it, I can't find anything that lets me provide myself this really simple convenience.

    Read the article

  • How do I print an array in Rails?

    - by Abid Hussain
    I am new to Rails and I am using Ruby version 1.9.3 and Rails version 3.0.0. I want to print an array in Rails. How do I do that? For example, we have to use print_r to print an array in PHP: <?php $a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z')); print_r ($a); ?> Output: <pre> Array ( [a] => apple [b] => banana [c] => Array ( [0] => x [1] => y [2] => z ) ) </pre> How do I print an array in Rails?

    Read the article

  • Doing permutation of different arrays in perl

    - by nubie2
    Hello! I want to do permutation in perl. For example I have three arrays. ["big", "tiny", "small"] and then I have ["red", "yellow", "green"] and also ["apple", "pear", "banana"]. How do I get: ["big", "red", "apple"] ["big", "red", "pear"] ..etc.. ["small", "green", "banana"] I understand this is called permutation. But I am not sure how to do it. Also I don't know how many arrays I can have. There may be three or four, so I don't want to do nested loop.

    Read the article

  • jQuery code to delete all spans with same content but keep one

    - by Axel
    Hello, Say i have the following html: <span class="fruit">Apple</span> <span class="fruit">banana</span> <span class="fruit">Apple</span> <span class="fruit">Apple</span> <span class="fruit">orange</span> I tried different methods but it didn't work, I want a jQuery code to remove all (.fruit) spans with same content but keep one (the first if possible), so i will end up with the following: <span class="fruit">Apple</span> <span class="fruit">banana</span> <span class="fruit">orange</span> Thank you

    Read the article

  • [PHP] Sorting data in an array

    - by kwokwai
    Hi all, I got an array which has 7 types of fruit: $fruits = array( "lemon", "orange", "banana", "apple", "cherry", "apricot", "Blueberry" ); I don't know how to print out the data in a way that the outcome will like this: <A> Apple, Apricot (Note that Apricot is followed by Apple in alphabetic order) <B> Banana <C> Cherry <L> Lemon <O> Orange I am sorry that the question may be a bit difficult. But please kindly help if you could.

    Read the article

  • Constraining enum value in method parameter

    - by fearofawhackplanet
    enum Fruit { Banana, Orange, Strawberry ... ... // etc, very long enum } PeelFruit(Fruit.Orange); PeelFruit(Fruit.Banana); PeelFruit(Fruit.Strawberry); // huh? can't peel strawberries! Sorry for the lame example, but hopefully you get the idea. Is there a way to constrain the enum values that PeelFruit will accept? Obvisouly I could check them in the method with a switch or something, but it would be cool if there was a way to do it that is a) a bit more compact, and b) would cause a compile time error, not a run time error. [Fruit = Orange,Bannana] void PeelFruit(Fruit fruit) { ... }

    Read the article

  • Is it considered bad form to execute a function within a conditional statement?

    - by michael
    Consider a situation in which you need to call successive routines and stop as soon as one returns a value that could be evaluated as positive (true, object, 1, str(1)). It's very tempting to do this: if (fruit = getOrange()) elseif (fruit = getApple()) elseif (fruit = getMango()) else fruit = new Banana(); return fruit; I like it, but this isn't a very recurrent style in what can be considered professional production code. One is likely to rather see more elaborate code like: fruit = getOrange(); if(!fruit){ fruit = getApple(); if(!fruit){ fruit = getMango(); if(!fruit){ fruit = new Banana(); } } } return fruit; According to the dogma on basic structures, is the previous form acceptable? Would you recommend it?

    Read the article

  • SQL query for getting data in two fields from one column.

    - by AmiT
    I have a table [Tbl1] containing two fields. ID as int And TextValue as nvarchar(max) Suppose there are 7 records. I need a resultset that has two columns Text1 and Text2. The Text1 should have first 4 records and Text2 should have remaining 3 records. [Tbl1] ID | TextValue 1. | Apple 2. | Mango 3. | Orange 4. | Pineapple 5. | Banana 6. | Grapes 7. | Sapota Now, the result-set should have Text1 | Text2 Apple | Banana Mango | Grapes Orange | Sapota Pineapple |

    Read the article

  • MySQL GROUP_CONCAT + IN() = missing data :-(

    - by Andrew Heath
    Example: Table: box boxID color 01 red 02 blue 03 green Table: boxHas boxID has 01 apple 01 pear 01 grapes 01 banana 02 lime 02 apple 02 pear 03 chihuahua 03 nachos 03 baby crocodile I want to query on the contents of each box, and return a table with each ID, color, and a column that concatenates the contents of each box, so I use: SELECT box.boxID, box.color, GROUP_CONCAT(DISTINCT boxHas.has SEPARATOR ", ") AS contents FROM box LEFT JOIN boxHas ON box.boxID=boxHas.boxID WHERE boxHas.has IN ('apple','pear') GROUP BY box.boxID ORDER BY box.boxID and I get the following table of results: boxID color contents 01 red apple, pear 02 blue apple, pear My question to you is: why isn't it listing ALL the has values in the contents column? Why is my WHERE statement also cropping my GROUP_CONCAT? The table I thought I was going to get is: boxID color contents 01 red apple, banana, grapes, pear 02 blue apple, lime, pear Although I want to limit my boxID results based upon the WHERE statement, I do not want to limit the contents field for valid boxes. :-/ Help?

    Read the article

  • Gradual memory leak in loop over contents of QTMovie

    - by Benji XVI
    I have a simple foundation tool that exports every frame of a movie as a .tiff file. Here is the relevant code: NSString* movieLoc = [NSString stringWithCString:argv[1]]; QTMovie *sourceMovie = [QTMovie movieWithFile:movieLoc error:nil]; int i=0; while (QTTimeCompare([sourceMovie currentTime], [sourceMovie duration]) != NSOrderedSame) { // save image of movie to disk NSAutoreleasePool *arp = [[NSAutoreleasePool alloc] init]; NSString *filePath = [NSString stringWithFormat:@"/somelocation_%d.tiff", i++]; NSData *currentImageData = [[sourceMovie currentFrameImage] TIFFRepresentation]; [currentImageData writeToFile:filePath atomically:NO]; NSLog(@"%@", filePath); [sourceMovie stepForward]; [arp release]; } [pool drain]; return 0; As you can see, in order to prevent very large memory buildups with the various transparently-autoreleased variables in the loop, we create, and flush, an autoreleasepool with every run through the loop. However, over the course of stepping through a movie, the amount of memory used by the program still gradually increases. Instruments is not detecting any memory leaks per se, but the object trace shows certain General Data blocks to be increasing in size. [Edited out reference to slowdown as it doesn't seem to be as much of a problem as I thought.] Edit: let's knock out some parts of the code inside the loop & see what we find out... Test 1 while (banana) { NSAutoreleasePool *arp = [[NSAutoreleasePool alloc] init]; NSString *filePath = [NSString stringWithFormat:@"/somelocation_%d.tiff", i++]; NSLog(@"%@", filePath); [sourceMovie stepForward]; [arp release]; } Here we simply loop over the whole movie, creating the filename and logging it. Memory characteristics: remains at 15MB usage for the duration. Test 2 while (banana) { NSAutoreleasePool *arp = [[NSAutoreleasePool alloc] init]; NSImage *image = [sourceMovie currentFrameImage]; [sourceMovie stepForward]; [arp release]; } Here we add back in the creation of the NSImage from the current frame. Memory characteristics: gradually increasing memory usage. RSIZE is at 60MB by frame 200; 75MB by f300. Test 3 while (banana) { NSAutoreleasePool *arp = [[NSAutoreleasePool alloc] init]; NSImage *image = [sourceMovie currentFrameImage]; NSData *imageData = [image TIFFRepresentation]; [sourceMovie stepForward]; [arp release]; } We've added back in the creation of an NSData object from the NSImage. Memory characteristics: Memory usage is again increasing: 62MB at f200; 75MB at f300. In other words, largely identical. It looks like a memory leak in the underlying system QTMovie uses to do currentFrameImage, to me.

    Read the article

  • Is it valid syntax to have ordered and unordered lists in sequence in markdown?

    - by nfm
    I just wrote some markdown and it doesn't seem to render correctly. Is it legal syntax to have an ordered list, followed by newlines, then followed by an unordered list? Or is this a bug in bluecloth? For example: 1. One 2. Two 3. Three * Apple * Banana * Carrot Bluecloth creates a single <ul> and nests apple, banana and carrot as <li>'s under it. Stackoverflow's markdown parser does this too. Am I just doing it wrong? Surely this is a common usage case...

    Read the article

  • GridView items are displaying the wrong drawables sometimes.

    - by originalbryan
    I've implemented a GridView based on this tutorial. It works great unless open up the search dialog or rotate the screen then scroll around. When the search dialog and virtual keyboard appear, the drawables for each of my grid items shift. I can click on them and they do what I expect, except the drawable is wrong. The same problem happens when I go into landscape mode and scroll around. If I scroll down, up, the down again, the drawables are shuffled. For better illustration, let's say I have three objects, each with an image. Obj A shows an Apple Obj B shows a Banana Obj C shows a Cantaloupe When the shift occurs I end up with: Obj A shows an Cantaloupe Obj B shows a Banana Obj C shows a Apple The problem isn't consistent between the two causes (search dialog and screen rotate n' scroll), but each cause itself is consistent. Scrolling around repeatedly reveals a pattern as does the search dialog appearing. How can I stop this from happening?

    Read the article

  • Finding matches between multiple JavaScript Arrays

    - by Chris Barr
    I have multiple arrays with string values and I want to compare them and only keep the matching results that are identical between ALL of them. Given this example code: var arr1 = ['apple', 'orange', 'banana', 'pear', 'fish', 'pancake', 'taco', 'pizza']; var arr2 = ['taco', 'fish', 'apple', 'pizza']; var arr3 = ['banana', 'pizza', 'fish', 'apple']; I would like to to produce the following array that contains matches from all given arrays: ['apple', 'fish', 'pizza'] I know I can combine all the arrays with var newArr = arr1.concat(arr2, arr3); but that just give me an array with everything, plus the duplicates. Can this be done easily without needing the overhead of libraries such as underscore.js? (Great, and now i'm hungry too!) EDIT I suppose I should mention that there could be an unknown amount of arrays, I was just using 3 as an example.

    Read the article

< Previous Page | 1 2 3 4 5 6 7  | Next Page >