Python btw.
n = ["Michael","Lieberman"]
def myFun(x):
for i in x:
return x[0] + x[1] # What happens when you change x to i?
print myFun(n)
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
Recognizable
Netherlands1552 Posts
Python btw. n = ["Michael","Lieberman"] | ||
ghrur
United States3786 Posts
On December 13 2012 01:47 Recognizable wrote: Hey, I have a question. I understand why the following prints: MichaelLieberman. But I don't understand if I change line 4 from, x[0] + x[1] to i[0] + i[1] it prints: Mi. n = ["Michael","Lieberman"] So when you change x to i, you're saying that for each element in the array, you return the first and the second element of the string i. So you return "Michael"[0] and "Michael"[1] which turns out to be "Mi". The reason it doesn't do "Li" too is because you're using return which stops the loop right there. So I think anyway. | ||
Recognizable
Netherlands1552 Posts
| ||
LocusCoeruleus
Norway32 Posts
For your first question, in the first iteration i = "Michael" and in the second iteration i = "Lieberman". For a list A, A[2] will return the third element. For the string S, how ever, S[2] gives you the the characters from 0 to (but not including) 2. (Reading everything above me again, I see that everything has been answered quite nicely, but whatever) | ||
Recognizable
Netherlands1552 Posts
![]() | ||
adwodon
United Kingdom592 Posts
Two questions, both completely separate so answer either if you can ![]() 1) I was just thinking coming home from work, I come from a physics background not a comp sci one so I'm not aware of some of the basics. Anyway, I remembered a question I had at an interview a while back about finding powers of 2. I mentioned several ways including looking at the binary, if it has a single 1, its a power of two. Just thinking about that again, it sounds straight forward but then I realized I actually don't know how I'd implement that, could anybody give me an example? C preferably but C++ / Java / Python / whatever non-obscure language is fine if it suits. 2) It's been a while since I did anything website related (5+ years), I'm considering setting up a personal site with a blog element, essentially to act as an both an extension for my CV and a kind of notebook / progress measure for personal projects. Is there any kind of IDE / package I should consider using? All I remember is Dreamweaver and I have no idea if thats still useful or if there are superior / solid alternatives or as its just a small site, if I'm better off just using Notepad++ and cranking it out by hand. I'm guessing HTML / CSS are still the main things with a splash of Javascript, but for a blog section is it reasonable to write something yourself, are there libraries / things to make this straight forward? I don't want a template site, but at the same time I don't really want to spend the next 6 months writing something with barely any functionality and full of annoying bugs, as I'd be learning every step of the way. What sort of languages would I expect to learn? I know a bit of Ruby but that's all as far as what I would consider web languages. If there are any good resources / websites then please do share, I could probably find out a lot of this by the powers of google but I find its often best to ask in a forum as you tend to get a more well rounded answer ![]() Thanks in advance! | ||
heishe
Germany2284 Posts
On December 13 2012 06:46 adwodon wrote: Hey guys, Two questions, both completely separate so answer either if you can ![]() 1) I was just thinking coming home from work, I come from a physics background not a comp sci one so I'm not aware of some of the basics. Anyway, I remembered a question I had at an interview a while back about finding powers of 2. I mentioned several ways including looking at the binary, if it has a single 1, its a power of two. Just thinking about that again, it sounds straight forward but then I realized I actually don't know how I'd implement that, could anybody give me an example? C preferably but C++ / Java / Python / whatever non-obscure language is fine if it suits. 2) It's been a while since I did anything website related (5+ years), I'm considering setting up a personal site with a blog element, essentially to act as an both an extension for my CV and a kind of notebook / progress measure for personal projects. Is there any kind of IDE / package I should consider using? All I remember is Dreamweaver and I have no idea if thats still useful or if there are superior / solid alternatives or as its just a small site, if I'm better off just using Notepad++ and cranking it out by hand. I'm guessing HTML / CSS are still the main things with a splash of Javascript, but for a blog section is it reasonable to write something yourself, are there libraries / things to make this straight forward? I don't want a template site, but at the same time I don't really want to spend the next 6 months writing something with barely any functionality and full of annoying bugs, as I'd be learning every step of the way. What sort of languages would I expect to learn? I know a bit of Ruby but that's all as far as what I would consider web languages. If there are any good resources / websites then please do share, I could probably find out a lot of this by the powers of google but I find its often best to ask in a forum as you tend to get a more well rounded answer ![]() Thanks in advance! On [1]. :
I'll leave it to you to figure out why this works. Should be a nice exercise in bitwise-operations. On [2]: As a project page, a simple plain text HTML site with some colored links that link to textual descriptions and downloads of your projects will suffice. Any person you'd want to be hired by will look for function, not form in your online CV. And for that, the only thing you really need is Notepad++ ![]() | ||
RoyGBiv_13
United States1275 Posts
On December 13 2012 06:46 adwodon wrote: Hey guys, Two questions, both completely separate so answer either if you can ![]() 1) I was just thinking coming home from work, I come from a physics background not a comp sci one so I'm not aware of some of the basics. Anyway, I remembered a question I had at an interview a while back about finding powers of 2. I mentioned several ways including looking at the binary, if it has a single 1, its a power of two. Just thinking about that again, it sounds straight forward but then I realized I actually don't know how I'd implement that, could anybody give me an example? C preferably but C++ / Java / Python / whatever non-obscure language is fine if it suits. 2) It's been a while since I did anything website related (5+ years), I'm considering setting up a personal site with a blog element, essentially to act as an both an extension for my CV and a kind of notebook / progress measure for personal projects. Is there any kind of IDE / package I should consider using? All I remember is Dreamweaver and I have no idea if thats still useful or if there are superior / solid alternatives or as its just a small site, if I'm better off just using Notepad++ and cranking it out by hand. I'm guessing HTML / CSS are still the main things with a splash of Javascript, but for a blog section is it reasonable to write something yourself, are there libraries / things to make this straight forward? I don't want a template site, but at the same time I don't really want to spend the next 6 months writing something with barely any functionality and full of annoying bugs, as I'd be learning every step of the way. What sort of languages would I expect to learn? I know a bit of Ruby but that's all as far as what I would consider web languages. If there are any good resources / websites then please do share, I could probably find out a lot of this by the powers of google but I find its often best to ask in a forum as you tend to get a more well rounded answer ![]() Thanks in advance! 1) Theres a few ways I can think to do this, but I like your way, so I'm going to use it. in C:
Or using a mask
EDIT: oooo I like heishe's implementation way better. 2) Wordpress has become the defacto standard for blogs. You can also check out Svbtle, which looks pretty cool. It's way easier than it ever has been to set up a personal blog. | ||
![]()
tofucake
Hyrule19083 Posts
| ||
RoyGBiv_13
United States1275 Posts
On December 13 2012 07:18 tofucake wrote: web design IDEs are the devil oh tofucake, its always 'X' is the devil with you. Tell us how you really feel about web design IDE's ^_^ | ||
![]()
tofucake
Hyrule19083 Posts
IDEs are responsible for sites like this | ||
adwodon
United Kingdom592 Posts
On December 13 2012 07:03 heishe wrote: On [1]. :
I'll leave it to you to figure out why this works. Should be a nice exercise in bitwise-operations. Looks shiney, I'll have a better look at it tomorrow (its about my bed time right now!). On December 13 2012 07:18 RoyGBiv_13 wrote: 2) Wordpress has become the defacto standard for blogs. You can also check out Svbtle, which looks pretty cool. It's way easier than it ever has been to set up a personal blog. Appreciate the info, I'll probably start with something simple and expand from there, Svbtle looks interesting o.O On December 13 2012 07:18 tofucake wrote: web design IDEs are the devil I do remember being told many years ago that things like Dreamweaver, whilst having their uses were generally for people with no interest or talent for actual code and also had a tendency to spew out rather unpleasant messes, I'm guessing things haven't changed in that sense much then! | ||
jjwhg
United States155 Posts
On December 13 2012 06:46 adwodon wrote: I was just thinking coming home from work, I come from a physics background not a comp sci one so I'm not aware of some of the basics. Anyway, I remembered a question I had at an interview a while back about finding powers of 2. I mentioned several ways including looking at the binary, if it has a single 1, its a power of two. Just thinking about that again, it sounds straight forward but then I realized I actually don't know how I'd implement that, could anybody give me an example? C preferably but C++ / Java / Python / whatever non-obscure language is fine if it suits. While this is probably overkill: In modern x86 CPUs there's actually an instruction that counts the number of bits set in a word, also known as the population count. The following GCC-specific C code int power_of_two(unsigned int x) compiles to 5 branch-free instructions on my machine (be sure to build with "-msse4.2") power_of_two: which I think is just about as efficient as you're going to get. | ||
Deleted User 101379
4849 Posts
On December 13 2012 07:18 tofucake wrote: web design IDEs are the devil I wholeheartedly agree. For a blog, just use wordpress. Doing it yourself is a waste of time. There is nothing wrong without using it and some existing theme, what matters in the end is the content anyways. | ||
heishe
Germany2284 Posts
E.g. 1110101011000101 should return 3; 1111100100100111... should return 5, etc. Checking single bits is trivial, but it's also incredibly slow. So far the only thing I've tried are lookup tables, which are even slower than looping through all bits manually (probably because a lookup table doesn't fit into the cache at all, resulting in tons of cache misses) | ||
AmericanUmlaut
Germany2577 Posts
Edit: Clarify what I mean with a bit of pseudocode
Oh, I see that you asked for counting from the left. The result is the same regardless of which direction you count, but if you want to start from the left, just use "val & 0b1000000000000000" and "val << 1" instead. | ||
heishe
Germany2284 Posts
On December 13 2012 23:21 AmericanUmlaut wrote: Why is checking single bits incredibly slow? Can't you just do sixteen bitwise shifts and use two variables to keep track of your current and max count of consecutive 1s? I already have a version that you're suggesting, but that piece of code is executed roughly 155 million times per second, which is why potentially 16 more loop iterations are incredibly slow. | ||
AmericanUmlaut
Germany2577 Posts
| ||
gyth
657 Posts
http://en.wikipedia.org/wiki/Find_first_set | ||
heishe
Germany2284 Posts
On December 14 2012 02:23 gyth wrote: There is probably an assembly instruction to do what you're looking for, or its complement. http://en.wikipedia.org/wiki/Find_first_set Well, I'm already using bsf/bsr in another part of the program, problem is as far as I know there's only the instruction that starts from the LSB and counts the first found set bit "starting from the right". If there was a similar instruction that would do the same thing but started "from the left", I could just invert the 16 bit and execute that instruction on it. But so far, I haven't found anything. (bsf and bsr produce the same results, they just start out differently.). Essentially bsf and bsr count trailing zeroes. I need something that counts leading zeroes. | ||
| ||
![]() StarCraft 2 StarCraft: Brood War Counter-Strike Super Smash Bros Other Games Organizations
StarCraft 2 • practicex StarCraft: Brood War![]() • intothetv ![]() • AfreecaTV YouTube • Kozan • IndyKCrew ![]() • LaughNgamezSOOP • Migwel ![]() • sooper7s League of Legends Other Games |
Sparkling Tuna Cup
PiGosaur Monday
LiuLi Cup
Replay Cast
The PondCast
RSL Revival
Maru vs SHIN
MaNa vs MaxPax
OSC
MaNa vs SHIN
SKillous vs ShoWTimE
Bunny vs TBD
Cham vs TBD
RSL Revival
Reynor vs Astrea
Classic vs sOs
BSL Team Wars
Team Bonyth vs Team Dewalt
CranKy Ducklings
[ Show More ] RSL Revival
GuMiho vs Cham
ByuN vs TriGGeR
Cosmonarchy
TriGGeR vs YoungYakov
YoungYakov vs HonMonO
HonMonO vs TriGGeR
[BSL 2025] Weekly
RSL Revival
Cure vs Bunny
Creator vs Zoun
BSL Team Wars
Team Hawk vs Team Sziky
Sparkling Tuna Cup
|
|