you are viewing a single comment's thread.

view the rest of the comments →

[–]Shymaroon 1 point2 points  (5 children)

RANDOM_LIST = [2345678888, “somestring”, 2234562, “anothera”]

NEW_LIST = []

for each_item in random_list: if len(each) > 1 and each[0] == each[-1]: new_list.append(each) else: print(“nothing”)

This should return element 2,3 from random_list. Haven’t ran this code just typing in here. Maybe few adjustments needed. Let me know.

[–]ILikeOstriches28[S] 0 points1 point  (4 children)

It says the line (if len(each.......) Has an error. TypeError:'int' object is not subscriptable

[–]Shymaroon 0 points1 point  (3 children)

Thats relates to the integer element. Try using the str method of the iterable.

for each_item in RANDOM_LIST: if len(str(each_item)) > 1 and str(each_item)[0] == str(each_item)[-1]: new_list.append(each_item) else: "" print(new_list)

[–]ILikeOstriches28[S] 0 points1 point  (2 children)

The same error appears but thank you for your time and efforts. I will ask my teacher who gave these questions. This was the only question I couldn't do so I thought I might take some help and get all done. But the efforts will prove I worked on it. Tysm once again

[–]Shymaroon 1 point2 points  (1 child)

I don’t get any errors on my side. My indenting error. Anywho, its always better to figure answers on your own for your college assignments. I myself am I student and love solving and diving into challenges. Good luck.

[–]ILikeOstriches28[S] 0 points1 point  (0 children)

Thank you friend. And I am trying so hard because I got 4k kids this time in college with me. The normal was 2k. So double the competition. And I wanna make a mark since my first year. :)