[Solved] How can i add the numbers of tuples from different lists of a a list in Python? [closed]

If the “list names” are always in the same order, you can do this using a list comprehension with zip and sum: >>> data = [[(‘Lista-A’, 1), (‘Lista-X’, 1), (‘Lista-Z’, 4)], [(‘Lista-A’, 2), (‘Lista-X’, 0), (‘Lista-Z’, 1)], [(‘Lista-A’, 5), (‘Lista-X’, 1), (‘Lista-Z’, 0)], [(‘Lista-A’, 0), (‘Lista-X’, 1), (‘Lista-Z’, 4)]] >>> [(col[0][0], sum(x for _, x … Read more

[Solved] python3 group items in list seperated by at least three empty items

This should work for you lst = [‘a’,’b’,’ c’, ”, ”, ”, ‘d’,’e’,’f’,”,’k’,’j’] res_lst = [] res_str=”” for i, item in enumerate(lst): res_str += item # Add current item to res_str # If next 3 items result is an empty string # and res_str has value if not ”.join(lst[i+1:i+3]) and res_str: res_lst.append(res_str) res_str=”” print(res_lst) Note: … Read more

[Solved] Python 3.4.2 | NameError: name ‘x’ is not defined

def checkDirection(chooseDirection): print(‘You have now entered the maze.’) time.sleep(0.5) if direction == str(Right or right): print (‘Congrats! You have turned the right way, you can live…’) time.sleep(1) print (‘For now o.O’) replace direction with chooseDirection because that is the argument you are trying to pass ( or take the value) for if else if you … Read more

[Solved] What function allows to ask wether a variable is an integer inside an if statement [closed]

You can do this using type or insinstance of python builtin module, like, if type(user_input) is int: # your code type returns the type of the obect. Or using insinstance, if isinstance(user_input, int): # your code isinstance return True if the object is instance of a class or it’s subclass. Now, in your code you … Read more

[Solved] Print Hexagonal pattern using asterisk [closed]

To work on arbitrary lengths>1, you have to change the second if-statement. I fixed the last one for you: sideLength = 5 totalLength = (sideLength) + 2*(sideLength-1) loop = 1 while loop<=totalLength : if loop==1 or loop==totalLength: print ” “*(sideLength-1) + “*”* sideLength + ” “*(sideLength-1) if loop>sideLength-1 and loop<= 2*sideLength-1: print “*” + ” … Read more

[Solved] Solving an equation with python

You can do things like this with the sympy library. http://docs.sympy.org/dev/index.html >>> from sympy import * >>> from sympy.solvers import solve >>> ca, ra = symbols(“ca ra”) >>> eq = -ra + (1.5 * (ca – (ra/2))/(1 + 0.8 * (ca – (ra/2)))) >>> print(eq) -ra + (1.5*ca – 0.75*ra)/(0.8*ca – 0.4*ra + 1) >>> … Read more

[Solved] This python code calls a function that returns a value but user input is asked twice [closed]

Within the function grades you’re asking for the score: score = float(input(“enter the score please”)) and then outside of the function, you’re also doing it: MyScore=float(input(“enter my score”)) Remove one of the two input statements, and it will only ask you the one time 🙂 def grades(score): if score<0.0 or score>1.0: return “Wrong score” elif … Read more

[Solved] How do I read twitter data saved in a txt file?

Since what you have is valid JSON, you can use a JSON parser: import json json_string = r”'{“created_at”:”Sun Jul 03 15:23:11 +0000 2016″,”id”:749624538015621120,”id_str”:”749624538015621120″,”text”:”Et hop un petit muldo dor\u00e9-indigo #enroutepourlaG2″,”source”:”\u003ca href=\”http:\/\/twitter.com\” rel=\”nofollow\”\u003eTwitter Web Client\u003c\/a\u003e”,”truncated”:false,”in_reply_to_status_id”:null,”in_reply_to_status_id_str”:null,”in_reply_to_user_id”:null,”in_reply_to_user_id_str”:null,”in_reply_to_screen_name”:null,”user”:{“id”:3050686557,”id_str”:”3050686557″,”name”:”Heresia”,”screen_name”:”Air_Et_Zia”,”location”:null,”url”:null,”description”:”Joueur de Dofus depuis 6 ans. Essentiellement ax\u00e9 PvP. Actuellement sur #Amayiro !”,”protected”:false,”verified”:false,”followers_count”:296,”friends_count”:30,”listed_count”:0,”favourites_count”:23,”statuses_count”:216,”created_at”:”Sat Feb 21 20:45:02 +0000 2015″,”utc_offset”:null,”time_zone”:null,”geo_enabled”:false,”lang”:”fr”,”contributors_enabled”:false,”is_translator”:false,”profile_background_color”:”000000″,”profile_background_image_url”:”http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png”,”profile_background_image_url_https”:”https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png”,”profile_background_tile”:false,”profile_link_color”:”9266CC”,”profile_sidebar_border_color”:”000000″,”profile_sidebar_fill_color”:”000000″,”profile_text_color”:”000000″,”profile_use_background_image”:false,”profile_image_url”:”http:\/\/pbs.twimg.com\/profile_images\/569237837581545472\/e_OJaGOl_normal.png”,”profile_image_url_https”:”https:\/\/pbs.twimg.com\/profile_images\/569237837581545472\/e_OJaGOl_normal.png”,”default_profile”:false,”default_profile_image”:false,”following”:null,”follow_request_sent”:null,”notifications”:null},”geo”:null,”coordinates”:null,”place”:null,”contributors”:null,”is_quote_status”:false,”retweet_count”:0,”favorite_count”:0,”entities”:{“hashtags”:[{“text”:”enroutepourlaG2″,”indices”:[34,50]}],”urls”:[],”user_mentions”:[],”symbols”:[]},”favorited”:false,”retweeted”:false,”filter_level”:”low”,”lang”:”fr”,”timestamp_ms”:”1467559391870″}”’ twit = json.loads(json_string) print (json.dumps(twit[“text”]))#or … Read more

[Solved] My program keeps getting an error called ‘inconsistent use of tabs and spaces’ when I add an else or elif statement [duplicate]

you have an indentation problem : if (input(“”).lower() == “yes”): gender_set() elif name.lower()==”dev mode”: print(“dev mode activated”) gender_set() else: name_set() solved My program keeps getting an error called ‘inconsistent use of tabs and spaces’ when I add an else or elif statement [duplicate]