As I am sharing my daily learning python learning progress, it is becoming more clear and evident to me that learning and sharing explaining concep...
For further actions, you may consider blocking this person and/or reporting abuse
Hi Arindam,
Another nice post. I thought you might be interested to know you don't need keys() to check if a key is in a dict. This is more idiomatic.
Similarly, we often use sets to deduplicate list and provide fast lookups because a set is stored as a hash of values.
The in keyword works on any iterable value... but I'm sure you will come to that soon enough. Enjoy your loops session. It's really cool stuff.
Cheers
Adrian
Thanks Adrian for the suggestion.
My intent was to demonstrate that keys() method is the default one. I forgot to mention explicitly.
I am so glad you found it worth a read :)
Good tutorial. Strangely though list(range(10)) does not seem to work on JupyterLab, but works seamlessly on Jupyter Notebook, it unfortunately took a while to figure this out... I assume you are coding in Jupyter Notebook? Also, for List Unpacking, lists with emojis did not work for me at all, was it supposed to?
TypeError Traceback (most recent call last)
in
7 print(merge_avengers) # ironman spiderman antman hulk
8
----> 9 range_of_numbers = list(range(10)) # quickly generates a list of specific range
10 print(range_of_numbers) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
11 another_range = list(range(0,5)) # with start stop
TypeError: 'list' object is not callable
I am not using Jupyter Notebooks. I am using REPL to test my code.
Pardon me, but I was not able to understand the error message properly.
Can you try running the code in REPL or any python code editor?
returns list index out of range. Does not generate any list for me.
this does not work either. Returns list object is not callable...
Thank you for pointing that out. There was a typo in my post. I have rectified it now.
The first one should be list(range(10))
The second one should work fine. Where are you trying to evaluate this?
Generally, list index out of range occurs if we try to access an element in a list which is not present.
Yes it works
HI Arindam!
at the part of
user = {'name': 'Max', 'age': 40, 'married': False}
print(user['name']) # Max
print(user['married'] # False
u missed an ')' after ['married']
And it took me half an hour to figure 😛
HI Arindam!
It s me again.
I found another missing ')' , this time i was faster.
at the part of
print(abstract['first'] # 123
print(abstract[True]) # 'hello
print(abstract[777]) # [1,3,4,5]
after ['first']
😝
Thanks Matt for taking the time to report this. Yeah sometimes it's the most silly things that we tend to ignore!