Split Each Line in TextFile By comma and insert each split to lists(2) [closed]How would you make a comma-separated string from a list of strings?How do you split a list into evenly sized chunks?How to split a string into a list?List vs tuple, when to use each?How to read a file line-by-line into a list?Split by comma and strip whitespace in Pythonput the words of a line in a array/list that can be referenced by an index using PythonPython splitting up line into separate listssort a .txt file after splitting the file to lines in Python 3Python - How to split a list into two separate lists dynamically
Adjective for when skills are not improving and I'm depressed about it
How to let cacti grow even if no player is near?
Return last number in sub-sequences in a list of integers
What is the name of this type of figure?
How to gracefully excuse yourself from a meeting due to emergencies such as a restroom break?
A game of red and black
Can black block with a hanging piece in a back rank mate situation?
Novel - Accidental exploration ship, broadcasts a TV show to let people know what they find
Constant Scan spooling
Why don't short runways use ramps for takeoff?
Can the additional attack from a Samurai's Rapid Strike have advantage?
Not taking Bereavement Leave
When did J.K. Rowling decide to make Harry and Ginny a couple?
mv Command Deleted Files In Source Directory and Target Directory
Why are prop blades not shaped like household fan blades?
Is this mechanically safe?
Applying for mortgage when living together but only one will be on the mortgage
Should students have access to past exams or an exam bank?
"DDoouubbllee ssppeeaakk!!"
How to crop this photo of water drops on a leaf to improve the composition?
Should I put my name first or last in the team members list?
Security measures that could plausibly last 150+ years?
How can a class have multiple methods without breaking the single responsibility principle
Why does Beijing's new Daxing airport have so few gates?
Split Each Line in TextFile By comma and insert each split to lists(2) [closed]
How would you make a comma-separated string from a list of strings?How do you split a list into evenly sized chunks?How to split a string into a list?List vs tuple, when to use each?How to read a file line-by-line into a list?Split by comma and strip whitespace in Pythonput the words of a line in a array/list that can be referenced by an index using PythonPython splitting up line into separate listssort a .txt file after splitting the file to lines in Python 3Python - How to split a list into two separate lists dynamically
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
im new to python and im looking for way to split text file output for 2 arrays and add them to ordered arrays
my text file looks like this
635992586,3718353429462250608
512101346,-5360506753539257325
464545614,2956310376478608644
448112867,-8362724325646859899
610706243,-3741068853182057127
583963913,-8936195924352638585
718532836,1783727609775441510
629842082,7499962062290955876
474659002,6480312120027362804
674787762,-3939702333232947477
457685296,-728255804367320714
445202854,-308676821356105829
762185989,-450762068712661096
345639374,6008304336530590920
561355579,-9018640421044127624
642304902,-3543147906925834368
493117557,2869749777644350319
393747681,812127138086916717
659310463,8747373126642898620
645009089,2643962417775803568
457146237,-5936132366977615159
725713836,-1906036700187282129
573896405,1703425138937300221
my goal is to create 2 arrays , and split it by this method
arr 1 takes the long fields(as string) that found in the right side of the list
and arr2 take the ints as string thats found left to the list
examp =
arr1[0] = 5360506753539257325
arr2[0] = 512101346
and keep until the end of the text file
string myArray[100];
int array_count = 0;
ifstream file((path+dicfile).c_str());
std::string line;
while (std::getline(file, line))
std::istringstream iss(line);
std::string str;
while (std::getline(iss, str, ','))
myArray[array_count] = str; // value to array
cout << str << "n";
strings.push_back(str);
array_count++;
python
closed as unclear what you're asking by Cody Gray♦ Mar 26 at 23:49
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
|
show 1 more comment
im new to python and im looking for way to split text file output for 2 arrays and add them to ordered arrays
my text file looks like this
635992586,3718353429462250608
512101346,-5360506753539257325
464545614,2956310376478608644
448112867,-8362724325646859899
610706243,-3741068853182057127
583963913,-8936195924352638585
718532836,1783727609775441510
629842082,7499962062290955876
474659002,6480312120027362804
674787762,-3939702333232947477
457685296,-728255804367320714
445202854,-308676821356105829
762185989,-450762068712661096
345639374,6008304336530590920
561355579,-9018640421044127624
642304902,-3543147906925834368
493117557,2869749777644350319
393747681,812127138086916717
659310463,8747373126642898620
645009089,2643962417775803568
457146237,-5936132366977615159
725713836,-1906036700187282129
573896405,1703425138937300221
my goal is to create 2 arrays , and split it by this method
arr 1 takes the long fields(as string) that found in the right side of the list
and arr2 take the ints as string thats found left to the list
examp =
arr1[0] = 5360506753539257325
arr2[0] = 512101346
and keep until the end of the text file
string myArray[100];
int array_count = 0;
ifstream file((path+dicfile).c_str());
std::string line;
while (std::getline(file, line))
std::istringstream iss(line);
std::string str;
while (std::getline(iss, str, ','))
myArray[array_count] = str; // value to array
cout << str << "n";
strings.push_back(str);
array_count++;
python
closed as unclear what you're asking by Cody Gray♦ Mar 26 at 23:49
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
3
Er, this is tagged Python...
– David Buck
Mar 26 at 23:31
This definitely appears to be C++ and not python. Specifically C++ because of the use of string.c_str() cplusplus.com/reference/string/string/c_str and std::
– Nick Vitha
Mar 26 at 23:34
1
Putting this on hold pending clarification of whether you want to do this in C++ or Python. Please edit your question and clarify. Make sure to update the tags.
– Cody Gray♦
Mar 26 at 23:49
@CodyGray: From the first sentence "im new to python", it seems clear enough to me...
– martineau
Mar 27 at 0:25
@martineau Did you miss the C++ code at the bottom of the question? How do you square that with your interpretation? Either way, guessing is not productive. If Wellzar wants an answer, we'll be happy to help, as soon as they clarify exactly what they want.
– Cody Gray♦
Mar 27 at 0:59
|
show 1 more comment
im new to python and im looking for way to split text file output for 2 arrays and add them to ordered arrays
my text file looks like this
635992586,3718353429462250608
512101346,-5360506753539257325
464545614,2956310376478608644
448112867,-8362724325646859899
610706243,-3741068853182057127
583963913,-8936195924352638585
718532836,1783727609775441510
629842082,7499962062290955876
474659002,6480312120027362804
674787762,-3939702333232947477
457685296,-728255804367320714
445202854,-308676821356105829
762185989,-450762068712661096
345639374,6008304336530590920
561355579,-9018640421044127624
642304902,-3543147906925834368
493117557,2869749777644350319
393747681,812127138086916717
659310463,8747373126642898620
645009089,2643962417775803568
457146237,-5936132366977615159
725713836,-1906036700187282129
573896405,1703425138937300221
my goal is to create 2 arrays , and split it by this method
arr 1 takes the long fields(as string) that found in the right side of the list
and arr2 take the ints as string thats found left to the list
examp =
arr1[0] = 5360506753539257325
arr2[0] = 512101346
and keep until the end of the text file
string myArray[100];
int array_count = 0;
ifstream file((path+dicfile).c_str());
std::string line;
while (std::getline(file, line))
std::istringstream iss(line);
std::string str;
while (std::getline(iss, str, ','))
myArray[array_count] = str; // value to array
cout << str << "n";
strings.push_back(str);
array_count++;
python
im new to python and im looking for way to split text file output for 2 arrays and add them to ordered arrays
my text file looks like this
635992586,3718353429462250608
512101346,-5360506753539257325
464545614,2956310376478608644
448112867,-8362724325646859899
610706243,-3741068853182057127
583963913,-8936195924352638585
718532836,1783727609775441510
629842082,7499962062290955876
474659002,6480312120027362804
674787762,-3939702333232947477
457685296,-728255804367320714
445202854,-308676821356105829
762185989,-450762068712661096
345639374,6008304336530590920
561355579,-9018640421044127624
642304902,-3543147906925834368
493117557,2869749777644350319
393747681,812127138086916717
659310463,8747373126642898620
645009089,2643962417775803568
457146237,-5936132366977615159
725713836,-1906036700187282129
573896405,1703425138937300221
my goal is to create 2 arrays , and split it by this method
arr 1 takes the long fields(as string) that found in the right side of the list
and arr2 take the ints as string thats found left to the list
examp =
arr1[0] = 5360506753539257325
arr2[0] = 512101346
and keep until the end of the text file
string myArray[100];
int array_count = 0;
ifstream file((path+dicfile).c_str());
std::string line;
while (std::getline(file, line))
std::istringstream iss(line);
std::string str;
while (std::getline(iss, str, ','))
myArray[array_count] = str; // value to array
cout << str << "n";
strings.push_back(str);
array_count++;
python
python
edited Mar 26 at 23:30
Wellzar
asked Mar 26 at 23:25
WellzarWellzar
216 bronze badges
216 bronze badges
closed as unclear what you're asking by Cody Gray♦ Mar 26 at 23:49
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Cody Gray♦ Mar 26 at 23:49
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Cody Gray♦ Mar 26 at 23:49
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
3
Er, this is tagged Python...
– David Buck
Mar 26 at 23:31
This definitely appears to be C++ and not python. Specifically C++ because of the use of string.c_str() cplusplus.com/reference/string/string/c_str and std::
– Nick Vitha
Mar 26 at 23:34
1
Putting this on hold pending clarification of whether you want to do this in C++ or Python. Please edit your question and clarify. Make sure to update the tags.
– Cody Gray♦
Mar 26 at 23:49
@CodyGray: From the first sentence "im new to python", it seems clear enough to me...
– martineau
Mar 27 at 0:25
@martineau Did you miss the C++ code at the bottom of the question? How do you square that with your interpretation? Either way, guessing is not productive. If Wellzar wants an answer, we'll be happy to help, as soon as they clarify exactly what they want.
– Cody Gray♦
Mar 27 at 0:59
|
show 1 more comment
3
Er, this is tagged Python...
– David Buck
Mar 26 at 23:31
This definitely appears to be C++ and not python. Specifically C++ because of the use of string.c_str() cplusplus.com/reference/string/string/c_str and std::
– Nick Vitha
Mar 26 at 23:34
1
Putting this on hold pending clarification of whether you want to do this in C++ or Python. Please edit your question and clarify. Make sure to update the tags.
– Cody Gray♦
Mar 26 at 23:49
@CodyGray: From the first sentence "im new to python", it seems clear enough to me...
– martineau
Mar 27 at 0:25
@martineau Did you miss the C++ code at the bottom of the question? How do you square that with your interpretation? Either way, guessing is not productive. If Wellzar wants an answer, we'll be happy to help, as soon as they clarify exactly what they want.
– Cody Gray♦
Mar 27 at 0:59
3
3
Er, this is tagged Python...
– David Buck
Mar 26 at 23:31
Er, this is tagged Python...
– David Buck
Mar 26 at 23:31
This definitely appears to be C++ and not python. Specifically C++ because of the use of string.c_str() cplusplus.com/reference/string/string/c_str and std::
– Nick Vitha
Mar 26 at 23:34
This definitely appears to be C++ and not python. Specifically C++ because of the use of string.c_str() cplusplus.com/reference/string/string/c_str and std::
– Nick Vitha
Mar 26 at 23:34
1
1
Putting this on hold pending clarification of whether you want to do this in C++ or Python. Please edit your question and clarify. Make sure to update the tags.
– Cody Gray♦
Mar 26 at 23:49
Putting this on hold pending clarification of whether you want to do this in C++ or Python. Please edit your question and clarify. Make sure to update the tags.
– Cody Gray♦
Mar 26 at 23:49
@CodyGray: From the first sentence "im new to python", it seems clear enough to me...
– martineau
Mar 27 at 0:25
@CodyGray: From the first sentence "im new to python", it seems clear enough to me...
– martineau
Mar 27 at 0:25
@martineau Did you miss the C++ code at the bottom of the question? How do you square that with your interpretation? Either way, guessing is not productive. If Wellzar wants an answer, we'll be happy to help, as soon as they clarify exactly what they want.
– Cody Gray♦
Mar 27 at 0:59
@martineau Did you miss the C++ code at the bottom of the question? How do you square that with your interpretation? Either way, guessing is not productive. If Wellzar wants an answer, we'll be happy to help, as soon as they clarify exactly what they want.
– Cody Gray♦
Mar 27 at 0:59
|
show 1 more comment
1 Answer
1
active
oldest
votes
You can open and read text files as a csv file with the csv
module that comes standard with python:
import csv
list1 = []
list2 = []
with open('file.txt', 'r') as file:
my_reader = csv.reader(file, delimiter=',')
for row in my_reader:
list1.append(row[0])
list2.append(row[1])
print(list1)
print(list2)
Output:
List1
['635992586', '512101346', '464545614', '448112867', '610706243', '583963913', '718532836', '629842082', '474659002', '674787762', '457685296', '445202854', '762185989', '345639374', '561355579', '642304902', '493117557', '393747681', '659310463', '645009089', '457146237', '725713836', '573896405']
List2
['3718353429462250608', '-5360506753539257325', '2956310376478608644', '-8362724325646859899', '-3741068853182057127', '-8936195924352638585', '1783727609775441510', '7499962062290955876', '6480312120027362804', '-3939702333232947477', '-728255804367320714', '-308676821356105829', '-450762068712661096', '6008304336530590920', '-9018640421044127624', '-3543147906925834368', '2869749777644350319', '812127138086916717', '8747373126642898620', '2643962417775803568', '-5936132366977615159', '-1906036700187282129', '1703425138937300221']
I think this accomplishes what you were asking, but this is in python (like you tagged) yet your example code is not in python...
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can open and read text files as a csv file with the csv
module that comes standard with python:
import csv
list1 = []
list2 = []
with open('file.txt', 'r') as file:
my_reader = csv.reader(file, delimiter=',')
for row in my_reader:
list1.append(row[0])
list2.append(row[1])
print(list1)
print(list2)
Output:
List1
['635992586', '512101346', '464545614', '448112867', '610706243', '583963913', '718532836', '629842082', '474659002', '674787762', '457685296', '445202854', '762185989', '345639374', '561355579', '642304902', '493117557', '393747681', '659310463', '645009089', '457146237', '725713836', '573896405']
List2
['3718353429462250608', '-5360506753539257325', '2956310376478608644', '-8362724325646859899', '-3741068853182057127', '-8936195924352638585', '1783727609775441510', '7499962062290955876', '6480312120027362804', '-3939702333232947477', '-728255804367320714', '-308676821356105829', '-450762068712661096', '6008304336530590920', '-9018640421044127624', '-3543147906925834368', '2869749777644350319', '812127138086916717', '8747373126642898620', '2643962417775803568', '-5936132366977615159', '-1906036700187282129', '1703425138937300221']
I think this accomplishes what you were asking, but this is in python (like you tagged) yet your example code is not in python...
add a comment |
You can open and read text files as a csv file with the csv
module that comes standard with python:
import csv
list1 = []
list2 = []
with open('file.txt', 'r') as file:
my_reader = csv.reader(file, delimiter=',')
for row in my_reader:
list1.append(row[0])
list2.append(row[1])
print(list1)
print(list2)
Output:
List1
['635992586', '512101346', '464545614', '448112867', '610706243', '583963913', '718532836', '629842082', '474659002', '674787762', '457685296', '445202854', '762185989', '345639374', '561355579', '642304902', '493117557', '393747681', '659310463', '645009089', '457146237', '725713836', '573896405']
List2
['3718353429462250608', '-5360506753539257325', '2956310376478608644', '-8362724325646859899', '-3741068853182057127', '-8936195924352638585', '1783727609775441510', '7499962062290955876', '6480312120027362804', '-3939702333232947477', '-728255804367320714', '-308676821356105829', '-450762068712661096', '6008304336530590920', '-9018640421044127624', '-3543147906925834368', '2869749777644350319', '812127138086916717', '8747373126642898620', '2643962417775803568', '-5936132366977615159', '-1906036700187282129', '1703425138937300221']
I think this accomplishes what you were asking, but this is in python (like you tagged) yet your example code is not in python...
add a comment |
You can open and read text files as a csv file with the csv
module that comes standard with python:
import csv
list1 = []
list2 = []
with open('file.txt', 'r') as file:
my_reader = csv.reader(file, delimiter=',')
for row in my_reader:
list1.append(row[0])
list2.append(row[1])
print(list1)
print(list2)
Output:
List1
['635992586', '512101346', '464545614', '448112867', '610706243', '583963913', '718532836', '629842082', '474659002', '674787762', '457685296', '445202854', '762185989', '345639374', '561355579', '642304902', '493117557', '393747681', '659310463', '645009089', '457146237', '725713836', '573896405']
List2
['3718353429462250608', '-5360506753539257325', '2956310376478608644', '-8362724325646859899', '-3741068853182057127', '-8936195924352638585', '1783727609775441510', '7499962062290955876', '6480312120027362804', '-3939702333232947477', '-728255804367320714', '-308676821356105829', '-450762068712661096', '6008304336530590920', '-9018640421044127624', '-3543147906925834368', '2869749777644350319', '812127138086916717', '8747373126642898620', '2643962417775803568', '-5936132366977615159', '-1906036700187282129', '1703425138937300221']
I think this accomplishes what you were asking, but this is in python (like you tagged) yet your example code is not in python...
You can open and read text files as a csv file with the csv
module that comes standard with python:
import csv
list1 = []
list2 = []
with open('file.txt', 'r') as file:
my_reader = csv.reader(file, delimiter=',')
for row in my_reader:
list1.append(row[0])
list2.append(row[1])
print(list1)
print(list2)
Output:
List1
['635992586', '512101346', '464545614', '448112867', '610706243', '583963913', '718532836', '629842082', '474659002', '674787762', '457685296', '445202854', '762185989', '345639374', '561355579', '642304902', '493117557', '393747681', '659310463', '645009089', '457146237', '725713836', '573896405']
List2
['3718353429462250608', '-5360506753539257325', '2956310376478608644', '-8362724325646859899', '-3741068853182057127', '-8936195924352638585', '1783727609775441510', '7499962062290955876', '6480312120027362804', '-3939702333232947477', '-728255804367320714', '-308676821356105829', '-450762068712661096', '6008304336530590920', '-9018640421044127624', '-3543147906925834368', '2869749777644350319', '812127138086916717', '8747373126642898620', '2643962417775803568', '-5936132366977615159', '-1906036700187282129', '1703425138937300221']
I think this accomplishes what you were asking, but this is in python (like you tagged) yet your example code is not in python...
answered Mar 26 at 23:33
ReedinationerReedinationer
4,1001 gold badge4 silver badges26 bronze badges
4,1001 gold badge4 silver badges26 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
3
Er, this is tagged Python...
– David Buck
Mar 26 at 23:31
This definitely appears to be C++ and not python. Specifically C++ because of the use of string.c_str() cplusplus.com/reference/string/string/c_str and std::
– Nick Vitha
Mar 26 at 23:34
1
Putting this on hold pending clarification of whether you want to do this in C++ or Python. Please edit your question and clarify. Make sure to update the tags.
– Cody Gray♦
Mar 26 at 23:49
@CodyGray: From the first sentence "im new to python", it seems clear enough to me...
– martineau
Mar 27 at 0:25
@martineau Did you miss the C++ code at the bottom of the question? How do you square that with your interpretation? Either way, guessing is not productive. If Wellzar wants an answer, we'll be happy to help, as soon as they clarify exactly what they want.
– Cody Gray♦
Mar 27 at 0:59