Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 calculation with list in list Gribouillis Posts: 1,768 Threads: 15 Joined: Jan 2018 Reputation: 168 Likes received: 422 #11 Aug-09-2019, 07:09 AM gianniskampanakis Wrote:Σε ευχαριστώ το type(i) εκτός από int τι τιμες μπορεί να πάρει στην περίπτωση μας ; I couldn't find a rule that enforces this, but try to use english in the forum as very few members read and understand greek. Note that `if type(i) == int` is not colloquial python code. The best way to do this is `if isinstance(i, int): ...` cvsae and micseydel like this post gianniskampanakis Programmer named Tim Posts: 7 Threads: 1 Joined: Aug 2019 Reputation: 0 Likes received: 0 #12 Aug-09-2019, 08:27 AM Thank you guys cvsae Silly Frenchman Posts: 28 Threads: 3 Joined: Jul 2019 Reputation: 3 Likes received: 2 #13 Aug-09-2019, 09:55 AM (Aug-09-2019, 06:39 AM)gianniskampanakis Wrote: Σε ευχαριστώ το type(i) εκτός από int τι τιμες μπορεί να πάρει στην περίπτωση μας ; you are welcome, can take str list dict etc.. below an example with a dict inside a list, using isinstance as Gribouillis mention https://python-forum.io/Thread-calculati...9#pid88479 ```l = [1,2,3,[1,2], {"test": 8}] def suml(l): s = 0 for i in l: if isinstance(i, int): s +=i elif isinstance(i, list): for t in i: s +=t elif isinstance(i, dict): for t in i: s +=i[t] return s``` gianniskampanakis Programmer named Tim Posts: 7 Threads: 1 Joined: Aug 2019 Reputation: 0 Likes received: 0 #14 Aug-09-2019, 12:01 PM (This post was last modified: Aug-09-2019, 12:03 PM by gianniskampanakis. Edited 2 times in total.) That's nice guys. I have never heard of insinstace use « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post I created a function that generate a list but the list is empty in a new .py file mrhopeedu 2 86 Oct-12-2019, 08:02 PM Last Post: mrhopeedu Creating a list from a comprehension using a list rm197 6 108 Sep-30-2019, 07:02 PM Last Post: rm197 Converting List into list of tuples ARV 4 266 Sep-28-2019, 04:58 AM Last Post: perfringo convert list of dict to dict of array of list with pop up kk230689 1 104 Sep-13-2019, 07:29 AM Last Post: perfringo removing quotes from a list and keep type list evilcode1 3 190 Aug-03-2019, 11:07 AM Last Post: perfringo Changing elements of a list to match another list rockproper 2 167 Jul-11-2019, 02:13 PM Last Post: ichabod801 Create new list from another list based on condition khalidreemy 1 234 Jun-11-2019, 10:21 AM Last Post: buran Iterating list of oredereddict for creating new list of ordereddict babypython 7 359 May-05-2019, 05:32 PM Last Post: Larz60+ reverse list, incl. nested list Livne_ye 3 275 May-04-2019, 12:34 PM Last Post: Livne_ye Convert List of Dictionary to dictionary of dictionary list in python kk230689 2 373 Apr-27-2019, 03:13 AM Last Post: perfringo

Forum Jump:

Users browsing this thread: 1 Guest(s)