Removing information from Tuples - tuples

I know tupules can't be edited but I'm planning on creating a new one. I'm importing information from a file and then cutting out the first name, last name, and year of birth. I just don't know how to edit it so I can cut out everything past the comma to get each element. Sorry if this is confusing!
Here's my code!
#Open file for employee information
employee_info_file=open('employees.txt','r')
#Loop for all employees
for line in employee_info_file:
#Read info and convert to tupule
employee_info=employee_info_file.readline()
employee_tupule=(employee_info)
#Designate first name, last name, and year born
first_name=
last_name=
year_born=
employee_tupule prints like this
Mark,Acrobello,8/12/1988
But each line has a different length for first name, last name, and DOB. lease help! thanks!

I hope I understood you correctly..
you are reading a file and in each line, there is an employee with some data in this format: "Mark,Acrobello,8/12/1988" and you want to have a tuple that has 3 elements, name, last name, and the date.
you can achieve that by using the split method on the string:
employee_tuple = tuple("Mark,Acrobello,8/12/1988".split(","))
print(employee_tople)
prints:
('Mark', 'Acrobello', '8/12/1988')

Related

Extract line-by-line info from multi-line cells in Google Sheets

A Google Sheet has multi-line information in its cells, e.g. address.
Each address can have a different number of lines, but we know:
1st line is always the name
Penultimate line is always the post code and city
Last line is always the country
And we are trying to split the address into 4 columns:
Name
Street address (i.e. the address left over after extracting name, post code & city, country)
Post code and city
Country
So col B (name) reads first line =REGEXEXTRACT(A1,”(\w.*)”)
Of course, I can figure out how many lines there are in each cell by counting next line character
=LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(10),””))
If the formula returns 6, then there are 7 lines
How do we get columns C (street address), D (postcode and city) and E (country) formulaically?
I mean, sure, I can get country for this cell with
=REGEXEXTRACT(A2,”(\n.*){6}”)
but I can’t copy the formula over….the 6 above is manual input, which defeats the purpose. Since this is regex, it obviously can’t take cell references instead of 6, e.g.
=REGEXEXTRACT(Amazon!B4,”(\n.*){F1}”)
(if for example, I stored in column F the number of next line characters in column A)
try:
=ARRAYFORMULA(IFNA({REGEXEXTRACT(A2:A, "(.*)\n"),
REGEXREPLACE(REGEXREPLACE(REGEXREPLACE(A2:A, "\n(.*)$", ), "\n(.*)$", ), "^(.*)\n", ),
REGEXEXTRACT(REGEXREPLACE(A2:A, "\n(.*)$", ), "(.*)$"),
REGEXEXTRACT(A2:A, "(.*)$")}))

Apply VLOOKUP to multiple rows

I am helping with a summer camp and want to be able to look up the amount that a parent has paid. My form gives me the results like this:
I want to be able to do an index lookup of the amount paid if I input either of the persons names in the row.
My code allows me to look up the last name and first name of the first parent but not of the second so I need to add an OR function in it somewhere but I'm not sure where.
=INDEX(FILTER(FACTURATION!G:G;FACTURATION!B:B=B3;FACTURATION!C:C=C3);1)
I tried this, but no luck:
=INDEX(OR(FILTER(FACTURATION!G:G;FACTURATION!B:B=B3;FACTURATION!C:C=C3);FILTER(FACTURATION!G:G;FACTURATION!E:E=B3;FACTURATION!F:F=C3)))
Link to spreadsheet
Try:
=IF(OR(List!$C2 = $B2; List!$C2 =$B2);List!$G2;IF(OR(List!$E2=$A2;List!$F2=$B2);List!$G2;List!$G2))
Does this formula work as you want:
=FILTER(List!G:G;(List!C:C=B3)+(List!B:B=A3))
I figured it out for anyone interested:
=FILTER(List!G:G;(List!C:C=B3)(List!B:B=A3)+(List!F:F=B3)(List!E:E=A3))
what I want listed
=FILTER(List!G:G;(List!C:C=B3)(List!B:B=A3)+(List!F:F=B3)(List!E:E=A3))
First two criterion (First Name and Last Name)
=FILTER(List!G:G;(List!C:C=B3)(List!B:B=A3)+(List!F:F=B3)(List!E:E=A3))
The second criterieon (First Name and Last Name)
I was missing the operators * = AND // + = OR
Thanks

How to get every combination of a combolist

I have a program where you can import a combolist, ex.
test:lol
hello:hi
sup:hey
The first one being the "username" and last one being the "password".
I want so that every single username will have a line with each password of the list. I would like all of this put into a separate string list.
Such as:
test:lol
test:hi
test:hey
hello:lol
hello:hi
hello:hey
sup:lol
sup:hi
sup:hey
I think this might be a really simple code, something to do with first separating the list into two lists, then for each username, add every password, but my brains can't really think of anything to come up with a solution for this.
thank you in advance :)
Yes, you're right.
Firs - get two lists users and passwords by separating each string by column.
Second traverse users and passwords and combine them. In pseudocode
foreach uName in users do
foreach pwd in passwords do
print user.concat(":").concat(pwd)
end
end
Explanation:
Get first `uName` from `users`
Get first `pwd` from `passwords`
output "`user`:`pwd`"
Get second `pwd` from `passwords`
output "`user`:`pwd`"
...
Get second `uName` from `users`
Get first `pwd` from `passwords`
output "`user`:`pwd`"
...
Feel free to ask, if something left unclear

SAS infile messy format of variable lengths

I have a messy file, where some of the columns are tab delimitated and some are comma.
My problem with the data set is reading the files with variable lengths
12 Stephen Cole, 33, Columbia, MO
5 Dave Anderson, 25*, Concord, OH
The first column is a ID (tab) the the name (comma) age (comma), active (presence of an asterisk after age), home (tab)
The * after the age indicates if they are inactive.
All the names start at column #19, but everything after that is variable lengths and column starts.
I want to read into a format where I finally get.
ID Name Age Active Home
12 Stephen Cole 33 Active Columbia, MO
5 Dave Anderson 25 Inactive Concord, OH
Thus far I have:
data marathon;
infile 'c:/file.txt' dlm=',' pad firstobs=12;
input #3 ID 3. #19 Name $CHAR13.;
Then I get stuck on how to read the rest. I am mostly thrown with how to read the asterisk next to the age as its own column. If I had that understood, I think I can handle the rest.
You have a couple of issues. First, you need to use delimited input, specifically you need to combine comma and tab into one set of delimiters - one way is shown below. Second, you have two fields that are nontrivial; the one with the asterisk needs to be parsed afterwards (I use compress to keep specifically digits in the first line, and to keep specifically asterisks in the second line). You also need to read city/state in separate fields and combine them together (I use catx).
data want;
infile "c:\temp\test.dat" dlm='092C'x;
input
id
name :$50.
age_active $
home_city :$25.
home_st $
;
age=input(compress(age_active,,'kd'),best.);
active = ifc(compress(age_active,'*','k')='*','Active','Inactive');
home = catx(', ',home_city,home_st);
run;
Watch your lengths, I suggest reasonable ones given my past experience but you could see longer names or cities easily.

Finding the filename with the latest modification date that fits a particular pattern

I have files at a particular path on my computer that look like "Report Name May 13.xls" and I'd like to be able to reference filenames dynamically. For example, say I wanted to return the latest file that fit the pattern "Report Name <>.xls" where <> is any particular text string. By "latest" I imply the most recent modified date.
You can extract the date piece from each file name easily enough, as in this Immediate window session.
strFile = "Report Name May 13.xls"
? Mid(strFile, 13)
May 13.xls
? Split(Mid(strFile, 13), ".")(0)
May 13
Assuming those dates are all from the current year, you can construct a full date string.
? Split(Mid(strFile, 13), ".")(0) & " " & Year(Date())
May 13 2013
Finally you can use CDate to convert that string to an actual Date/Time value.
? CDate(Split(Mid(strFile, 13), ".")(0) & " " & Year(Date()))
5/13/2013
So you could have a variable to store the maximum date, walk your list of file names, determine the date associated with each, and store the max date value as needed.
That should not be too difficult. A greater concern for me is the file names do not include the year. So that leaves me wondering what will happen on Jan 1 2014. Will you discard all the .xls files and start over?