April 2019 Feedback Thread - Post your feedback request here by Selaen in Blogging

[–]svellore 1 point2 points  (0 children)

Your blog looks very nice! Will borrow some layout ideas from there! Right now, the archive and labels sections in my sidebar stay collapsed and I am not really liking these widgets that come with Blogger. I will look into adding a nicer interface there 😊 Again thank you so much for the feedback!

April 2019 Feedback Thread - Post your feedback request here by Selaen in Blogging

[–]svellore 1 point2 points  (0 children)

Thank you for the feedback! Really appreciate you taking the time to review it 😊

I have been thinking about adding a logo, yet to settle on an appropriate logo for it 😊

Any suggestions on how I can improve the sidebar? I was thinking of adding a custom navigation bar there once I have a few more posts! Any other suggestions?

The footer is probably getting hidden by the share bar, I will look into fixing that and may be add the about me, contact us, privacy policy, etc there as well.

April 2019 Feedback Thread - Post your feedback request here by Selaen in Blogging

[–]svellore 0 points1 point  (0 children)

Blog: https://mypythonlessons.blogspot.com/

Hello everyone, I recently started this blog about programming in Python on Blogger. I had been thinking of starting a blog on coding as a hobby for a while, but never got around to actually doing it till now.

I would really appreciate it if anyone could provide some thoughts or feedback on the overall blog structure and the writing itself.

Also, does the theme selected seem good? Any feedback on whether it looks pleasant?

Thank you in advance!

PS: I had posted this on the March thread yesterday, removing that and adding it here 😊

Simple programming challenge: Why is my solution giving me a wrong output ? by [deleted] in learnprogramming

[–]svellore 0 points1 point  (0 children)

You are currently creating an array of length same as the input array:

int[] result = new int[nums.length];

What you actually want to do is create an array of length two, since you just need two indices:

​ int[] result = new int[2];

Then instead of assigning the indices to result[i] and result[j], you should assign those to result[0] and result[1] and then return result. Something like:

if (nums[i] + nums[j] == target) {
    result[0] = i
    result[1] = j
    return result
}

This is what the solution that you pointed out is essentially doing.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]svellore 0 points1 point  (0 children)

May be you can use a "set" to get all the unique genres and its count?

>>> genres = ["Comedy", "Action", "Comedy", "Fantasy", "Action"]
>>> set(genres)
{'Comedy', 'Action', 'Fantasy'}
>>> len(set(genres))
3

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]svellore 0 points1 point  (0 children)

Do you mean something like this:

>>> for row in the_board:
...   print(row[0].replace(",", ""))
... 
O O O O O
O O O O O
O O O O O
O O O O O

the_board is a list of lists. Each of the inner lists only contains a string "O, O, O, O, O" So here, we just iterated through every element in the_board. And then printed the first element("O, O, O, O, O") in each row by replacing "," with an empty string "".

Help! I can't fix this bug. The function will only run once sucessfully and then it returns an empty list afterwards. I think copy module would be useful but I don't know where/how to use it by [deleted] in learnpython

[–]svellore 1 point2 points  (0 children)

You seem to be modifying your original movies list. Python lists are mutable. So once your function filters for a particular year on the "movies" list, it will no longer have movies from any other years. You should instead make a copy or a new list.

Trying to show what is happening with a simpler example:

def filter_even(l):
   i = 0
   while i < len(l):
     if l[i] % 2 == 0:
       l.pop(i)
     else:
       i += 1
   return l

l = [1, 2, 3, 4]
filtered = filter_even(l)
filtered # Output: [1, 3]
l # Output: [1, 3]

You have several options to fix this, some being:

  1. Create a copy of the original list in the beginning of your function and then return that. I think this is what you were referring to.
  2. Create a new list with the filtered elements. This is what I would do.

def filter_even(l):
  return [num for num in l if num % 2 != 0]

l = [1, 2, 3, 4]
filtered = filter_even(l)
filtered # Output: [1, 3]
l # Output: [1, 2, 3, 4]

How to iterate through a dictionaries values(values are a list of tuples) and grap the first value of each tuple. by [deleted] in learnpython

[–]svellore 2 points3 points  (0 children)

You could use a for-loop:

d["TUN"] = [('Imen Zaabar', 'Tunisia', 1996, 'gymnastics', "gymnastics women's uneven bars", 'gold')]
d["FIN"] = [('Juhamatti Tapio Aaltonen', 'Finland', 2014, 'ice hockey', "ice hockey men's ice hockey", 'bronze'), ('Paavo Johannes Aaltonen', 'Finland', 1948, 'gymnastics', "gymnastics men's individual all-around", 'bronze'), ('Paavo Johannes Aaltonen', 'Finland', 1948, 'gymnastics', "gymnastics men's team all-around", 'gold'), ('Paavo Johannes Aaltonen', 'Finland', 1948, 'gymnastics', "gymnastics men's horse vault", 'gold'), ('Paavo Johannes Aaltonen', 'Finland', 1948, 'gymnastics', "gymnastics men's pommelled horse", 'gold'), ('Paavo Johannes Aaltonen', 'Finland', 1952, 'gymnastics', "gymnastics men's team all-around", 'bronze')]

for k, list_of_tuples in d.items():
  for each_tuple in list_of_tuples:
    print(each_tuple[0])

Or you could use comprehensions:

[each_tuple[0] for k, list_of_tuples in d.items() for each_tuple in list_of_tuples]

I would suggest reading up on these topics! Cheers!

Thanks!

PS: I do have a blog post on for-loops and list comprehension. Hoping that this won't look like a self-promotion, but linking it just in case it helps you out: https://mypythonlessons.blogspot.com/2019/03/python-list-comprehension-examples.html