Hi I have a variables that is declared outsides fucntions. How can I use and change these variables inside function usign Python? thank you
You can use Counter if you want to do multiple count of the list from collections import Counter list = ['Jones','Adams','Frank','John','Lopez','Jones','Smith','Ivan','Julian','Carlos','Adams','Frank','Jones','John','Ivan'] print(Counter(list)) Result: Counter({'Jones': 3, 'Adams': 2, 'Frank': 2, 'JRead more
You can use Counter if you want to do multiple count of the list
1 2 3 4 | from collections import Counter list = ['Jones','Adams','Frank','John','Lopez','Jones','Smith','Ivan','Julian','Carlos','Adams','Frank','Jones','John','Ivan'] print(Counter(list)) |
Result:
1 2 | Counter({'Jones': 3, 'Adams': 2, 'Frank': 2, 'John': 2, 'Ivan': 2, 'Lopez': 1, 'Smith': 1, 'Julian': 1, 'Carlos': 1}) |
See less
Follow this example to create a variable outside functions, and use it inside the functions: MyVariable = 99 #this is a global variable def changeAndPrint_GlobalVariable(): global MyVariable #use global variable in this function with "global" keyword print('Global variable "MyVariable" before changeRead more
Follow this example to create a variable outside functions, and use it inside the functions:
This code will print:
See less