python add string and number in array

Solutions on MaxInterview for python add string and number in array by the best coders in the world

showing results for - "python add string and number in array"
Gaël
14 Jun 2017
1numbers = []
2animals = []
3with open('textfile.txt') as f:
4    for x in f:
5        try:
6            numbers.append(int(x.replace("\n", "")))
7        except:
8            animals.append(str(x.replace("\n", "")))
9print(numbers)
10print(animals)
11
12# Output
13# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
14# ['dog', 'cat', 'fish', 'bird']
queries leading to this page
python split string in arrayadd string in array pythonpython insert string in arraypython split arraysplit number into array pythonpython check if string is in arraypython add stringg to arrayadd element to string array pythonpython split values with otsu arraycheck if value is array pythonpython check if string lies in arraycheck if string is not their in array of strings pythonpython test if string or arraypython check string or number arraypython add string to arraypython check array for stringcheck if string in array pythonseparate numbers and strings into array pythoncheck if array contain number pythonsplit text in array pythonsplit values in array pythoncheck if array intercet pythonhow to append string and arrays to an array pythonadd elements in string array pythonhow to add string to array in pythonadd string to an array pythoncheck if array elements not in string pythonpython check string in arrayadd sting to array pythoncheck if a string is in array pythonadd array of string to array pythoncheck if string not in array pythonpython check if number in arrayadd values of array to string in pythoncheck if it 27s a string or array pythonhow to add string into array pythonpython check if type is string arrayhow to check if a string contain an array of values pythonappend string of python array check if variable is array or string in pythonpython check if string present in array of stringspython string split arraysplit string into array pythonsplit string and put it into an array pythonpython split string into arraypython add string and number in array