Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

sasogeek

  • 2 years ago

I have an array of 100000 integers in a listed form and don't have commas separating them. what's the easiest way to put commas at the end of each number. example of how the array is listed [1234 234 3654 48356 51235] the numbers are from 1 to 100000 and no number is repeated. i want to place commas at the ends so that it looks like this [1234, 234, 3654, 48356, 5123] do I have to put the commas there manually or there's an easier way cos the array is too huge. :/

  • This Question is Closed
  1. saruz
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    if its php there is str_replace........ it would be better if you tell which programming lanugage are you using

  2. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I'm using notepad++ so if you know a shortcut to doing this please let me know, I've already started putting commas there one after the other but it's going to take too much time :/ i don't need a program to do this, I just want the easiest way to put the commas there in the text editor.

  3. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    integers

  4. saruz
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    array...i guess

  5. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    yh

  6. NotSObright
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Tell me exactly what it is and what you need Is it an array and you want as a string

  7. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    it is an array of 100 thousand integers, but there's no comma after each integer so if i write a program to deal with the array, it assumes the array is only the first integer and ignores the rest and actually gives me an error because it expects "]" after the first integer. I need an easier way to put commas after each integer to include them in the array.

  8. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    [1234 234 3654 48356 51235] is the same as [1234 234 3654 48356 51235] but in arrays, you use commas to separate the objects, not a space, so the program reads the array as an error. i want to put commas so that the array becomes [1234, 234, 3654, 48356, 51235]

  9. NotSObright
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Sorry no solution to your problem it is something of a feature of notepad++ you must ask sm'one who know it

  10. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    but there's too many integers, so i'm only asking for an easier way to put the commas, not sure if you get my point :/

  11. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I guess i'm gonna have to do it manually :(

  12. agdgdgdgwngo
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    if these are separated by lines, then there's probably a one-liner python solution. http://ideone.com/52nka

  13. agdgdgdgwngo
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    You can probably record a macro (I'm unfamiliar with how it's done in notepad++) that goes after each 'word' (each number); appending a comma to the end.

  14. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    how do you record a macra? i'm an npp noob

  15. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I know of the .join array function but it will only output it in the shell, if only i could do it somewhere i could copy and paste, then i'd do that with ruby and copy all the numbers... :/

  16. agdgdgdgwngo
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    try it on http://ideone.com :-D

  17. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    thanks :)

  18. Ishaan94
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Is \n for new line character? Why'd you used three double quotes?

  19. agdgdgdgwngo
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    I used 3 quotes because they allow you to enter multiple lines of data into the string, and they preserve newlines and stuff; maybe the single pair of quotes will be alright too lets try: http://ideone.com/utOdJ nope :(

  20. Ishaan94
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Oh, so what is .join function for and lambda (does it have something to do with lambda calculus you used to talk about a few months back)?

  21. agdgdgdgwngo
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    the join method appends the thing to the right of the dot (an empty string in this case) to every element of the iterable on the right of the dot (a list of characters) the lambda keyword creates an anonymous function (really an expression in Python); lambda x, y: z is effectively equivalent to def something(x, y): return z but it won't be called 'something' unless you do something like something = lambda x,y: z I don't think it has anything to do with lambda calculus :-P

  22. agdgdgdgwngo
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    appends the object to the left* of the dot... sorry :-P

  23. bmp
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Ah, Python, the master of scripting languages. I did something similar, but I was trying to extracting values from a column :-) Nice job, agdgdgdgwngo.

  24. Ishaan94
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Oh I see... thank you agd

  25. agdgdgdgwngo
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    also, the join method is recursively applied to the things in the list http://ideone.com/pwaf1

  26. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    it didn't work with my source code cos ideone also see's my array as invalid and gives me an error so i'm using ur python source and replacing the sample array with the actual one to see how it comes out if u don't mind me using it :/

  27. agdgdgdgwngo
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    can you post your code?

  28. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    sure, i clicked on new code so lemme type that out again and give it to you

  29. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    never mind i'll type it here

  30. agdgdgdgwngo
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    http://ideone.com/xloiE this one right?

  31. agdgdgdgwngo
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    hahaha that is one huge array

  32. agdgdgdgwngo
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    won't fit on ideone which is why you got error ther :-D

  33. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I'll do it bit by bit :) a couple of 1000's at a time

  34. Ishaan94
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    \[\color{green}{\large{\mathsf{\text{ I hereby declare this thread as the longest thread on OpenStudy!}}}}\]

  35. Ishaan94
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    btw what kind of information is stored in this array?

  36. Ishaan94
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Population of 100,000 villages in Ghana?

  37. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    homework... the design and analysis of algorithms I class of stanford's online course, i'm sure u have an idea cos u gave me a link to that program stanford was offering

  38. Ishaan94
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Oh no I didn't join the course but it's good thing you're following it! Good Luck (y)

  39. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    i need the array well in place before my program will work, i didn't want to type the commas manually before running the program so... yeah :) my program works fine with other arrays though, i just need to run it on this array which is one heck of a waste of time putting commas..

  40. Ishaan94
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    What do you think would be size of this digit '82586' in bytes? 2?

  41. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    5bits

  42. Ishaan94
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    5 wow, most of the digits are 5 digits in your list or array... mean size must be around 4.8, I guess... 4.8 * 100,000 = 480,000 bits of information on your RAM

  43. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    lol i'm only saying 5 bits cos i know every number represents a bit... you typed 5 numbers... i presume that to be 5 bits, i don't know for sure but that's what i'll tell anyone who ask's me, from the fair knowledge i have. i won't conclude on that though but yeah :)

  44. Ishaan94
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    but I don't think it works that way, I think RAM stores it in the form of integer and an integer occupies like 2 bytes... so 200,000 bytes of information.

  45. agdgdgdgwngo
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    the http://algo-class.org is online now? :-D thanks for the heads up! so I'm taking MITx's https://6002x.mitx.mit.edu/ , berkeley's http://saas-class.org , and stanford's https://www.coursera.org/modelthinking/class , http://algo-class.org , http://www.nlp-class.org/ and udacity's CS101 and CS373

  46. agdgdgdgwngo
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    oh and https://www.coursera.org/crypto/class

  47. Ishaan94
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Wow agd, so many courses...

  48. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I signed up for the crypto class too but i'm not sure i'm enrolling in that :/

  49. sasogeek
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    actually i signed up for 5 classes but i'm not sure i'm enrolling in all... i have to check my schedule :)

  50. nczempin
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    lambda in python and other languages is indeed based on lambda calculus

  51. nczempin
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    how far in is CS373?

  52. nczempin
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    http://en.wikipedia.org/wiki/Lambda_calculus#Lambda_calculus_and_programming_languages

  53. Tomas.A
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    just use find & replace function of notepad++ (or any other editor has that function too) since it's seperated by new line, you search for "\n" (which means new line) and replace it to ",\n" (comma and new line) and you don't need to bother with programming :D

  54. Tomas.A
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    oh and why algorhitm class didn't announce that they finally starting, i just got email some weeks ago that it will be delayed

  55. rsmith6559
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    notepad++ sounds like Windows to me, wouldn't that make the "newline" "\r\n"?

  56. Tomas.A
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ah yeah they have carriage return and new line

  57. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.