I have a table that keeps track of scores from a test. It compares the row with someone's answers to the row with the correct data:
A B C D E
+--------------+-----+-----+-----+-------+
1 | | Q1 | Q2 | Q3 | Score |
+--------------+-----+-----+-----+-------+
2 | Answers | C | B | A | |
+--------------+-----+-----+-----+-------+
3 | George | C | A | B | 1 |
4 | Judith | C | C | A | 2 |
5 | James | A | B | C | 1 |
+--------------+-----+-----+-----+-------+
The formula behind the Score column is:
=arrayformula(sumproduct(($B$2:$D$2=B3:D3)))
The first part of sumproduct is a static reference to the Answers row. The second part is comparing it against the row it's on. However I want to add an exception: if the Answers row contains an asterisk it should consider all answers correct:
A B C D E
+--------------+-----+-----+-----+-------+
1 | | Q1 | Q2 | Q3 | Score |
+--------------+-----+-----+-----+-------+
2 | Answers | C | * | A | |
+--------------+-----+-----+-----+-------+
3 | George | C | A | B | 2 |
4 | Judith | C | C | A | 3 |
5 | James | A | B | C | 1 |
+--------------+-----+-----+-----+-------+
How would I be able to do this?
Please try:
=arrayformula(sumproduct(($B$2:$D$2=B3:D3)+($B$2:$D$2="*")))
=IF(OR($B$2=B3, $B$2="*"), 1, )+
IF(OR($C$2=C3, $C$2="*"), 1, )+
IF(OR($D$2=D3, $D$2="*"), 1, )
this will cover up to 51 questions (columns / range of B:AZ)
=IF(LEN($B$2),IF(OR($B$2=B3,$B$2="*"),1,),)+
IF(LEN($C$2),IF(OR($C$2=C3,$C$2="*"),1,),)+
IF(LEN($D$2),IF(OR($D$2=D3,$D$2="*"),1,),)+
IF(LEN($E$2),IF(OR($E$2=E3,$E$2="*"),1,),)+
IF(LEN($F$2),IF(OR($F$2=F3,$F$2="*"),1,),)+
IF(LEN($G$2),IF(OR($G$2=G3,$G$2="*"),1,),)+
IF(LEN($H$2),IF(OR($H$2=H3,$H$2="*"),1,),)+
IF(LEN($I$2),IF(OR($I$2=I3,$I$2="*"),1,),)+
IF(LEN($J$2),IF(OR($J$2=J3,$J$2="*"),1,),)+
IF(LEN($K$2),IF(OR($K$2=K3,$K$2="*"),1,),)+
IF(LEN($L$2),IF(OR($L$2=L3,$L$2="*"),1,),)+
IF(LEN($M$2),IF(OR($M$2=M3,$M$2="*"),1,),)+
IF(LEN($N$2),IF(OR($N$2=N3,$N$2="*"),1,),)+
IF(LEN($O$2),IF(OR($O$2=O3,$O$2="*"),1,),)+
IF(LEN($P$2),IF(OR($P$2=P3,$P$2="*"),1,),)+
IF(LEN($Q$2),IF(OR($Q$2=Q3,$Q$2="*"),1,),)+
IF(LEN($R$2),IF(OR($R$2=R3,$R$2="*"),1,),)+
IF(LEN($S$2),IF(OR($S$2=S3,$S$2="*"),1,),)+
IF(LEN($T$2),IF(OR($T$2=T3,$T$2="*"),1,),)+
IF(LEN($U$2),IF(OR($U$2=U3,$U$2="*"),1,),)+
IF(LEN($V$2),IF(OR($V$2=V3,$V$2="*"),1,),)+
IF(LEN($W$2),IF(OR($W$2=W3,$W$2="*"),1,),)+
IF(LEN($X$2),IF(OR($X$2=X3,$X$2="*"),1,),)+
IF(LEN($Y$2),IF(OR($Y$2=Y3,$Y$2="*"),1,),)+
IF(LEN($Z$2),IF(OR($Z$2=Z3,$Z$2="*"),1,),)+
IF(LEN($AA$2),IF(OR($AA$2=AA3,$AA$2="*"),1,),)+
IF(LEN($AB$2),IF(OR($AB$2=AB3,$AB$2="*"),1,),)+
IF(LEN($AC$2),IF(OR($AC$2=AC3,$AC$2="*"),1,),)+
IF(LEN($AD$2),IF(OR($AD$2=AD3,$AD$2="*"),1,),)+
IF(LEN($AE$2),IF(OR($AE$2=AE3,$AE$2="*"),1,),)+
IF(LEN($AF$2),IF(OR($AF$2=AF3,$AF$2="*"),1,),)+
IF(LEN($AG$2),IF(OR($AG$2=AG3,$AG$2="*"),1,),)+
IF(LEN($AH$2),IF(OR($AH$2=AH3,$AH$2="*"),1,),)+
IF(LEN($AI$2),IF(OR($AI$2=AI3,$AI$2="*"),1,),)+
IF(LEN($AJ$2),IF(OR($AJ$2=AJ3,$AJ$2="*"),1,),)+
IF(LEN($AK$2),IF(OR($AK$2=AK3,$AK$2="*"),1,),)+
IF(LEN($AL$2),IF(OR($AL$2=AL3,$AL$2="*"),1,),)+
IF(LEN($AM$2),IF(OR($AM$2=AM3,$AM$2="*"),1,),)+
IF(LEN($AN$2),IF(OR($AN$2=AN3,$AN$2="*"),1,),)+
IF(LEN($AO$2),IF(OR($AO$2=AO3,$AO$2="*"),1,),)+
IF(LEN($AP$2),IF(OR($AP$2=AP3,$AP$2="*"),1,),)+
IF(LEN($AQ$2),IF(OR($AQ$2=AQ3,$AQ$2="*"),1,),)+
IF(LEN($AR$2),IF(OR($AR$2=AR3,$AR$2="*"),1,),)+
IF(LEN($AS$2),IF(OR($AS$2=AS3,$AS$2="*"),1,),)+
IF(LEN($AT$2),IF(OR($AT$2=AT3,$AT$2="*"),1,),)+
IF(LEN($AU$2),IF(OR($AU$2=AU3,$AU$2="*"),1,),)+
IF(LEN($AV$2),IF(OR($AV$2=AV3,$AV$2="*"),1,),)+
IF(LEN($AW$2),IF(OR($AW$2=AW3,$AW$2="*"),1,),)+
IF(LEN($AX$2),IF(OR($AX$2=AX3,$AX$2="*"),1,),)+
IF(LEN($AY$2),IF(OR($AY$2=AY3,$AY$2="*"),1,),)+
IF(LEN($AZ$2),IF(OR($AZ$2=AZ3,$AZ$2="*"),1,),)
and here is "Formula Generator" sheet for that
I'm trying to get some details about movies from IMDB.
For that I'm using IMDBpy with following code:
import imdb
ia = imdb.IMDb()
top250 = ia.get_top250_movies()
i = 0;
for topmovie in top250:
# First, retrieve the movie object using its ID
movie = ia.get_movie(topmovie.movieID)
cast = movie.get('cast')
topActors = 3
i = i+1;
actor_names = [actor['name'] for actor in cast[:topActors]]
#director_name = [director['director'] for director in cast[:topActors]]
if i <= 10:
print(movie, ';', ' | '.join(movie['genres']),
';', ' | '.join(actor_names),
';', ' | '.join(str(movie['director']))
);
else:
break;
However when I run my code I am getting my results with this format:
The Shawshank Redemption ; Drama ; Tim Robbins | Morgan Freeman | Bob Gunton ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 0 | 0 | 1 | 1 | 0 | 4 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | D | a | r | a | b | o | n | t | , | | F | r | a | n | k | _ | > | ]
The Godfather ; Crime | Drama ; Marlon Brando | Al Pacino | James Caan ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 0 | 0 | 0 | 3 | 3 | 8 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | C | o | p | p | o | l | a | , | | F | r | a | n | c | i | s | | F | o | r | d | _ | > | ]
The Godfather: Part II ; Crime | Drama ; Al Pacino | Robert Duvall | Diane Keaton ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 0 | 0 | 0 | 3 | 3 | 8 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | C | o | p | p | o | l | a | , | | F | r | a | n | c | i | s | | F | o | r | d | _ | > | ]
The Dark Knight ; Action | Crime | Drama | Thriller ; Christian Bale | Heath Ledger | Aaron Eckhart ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 6 | 3 | 4 | 2 | 4 | 0 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | N | o | l | a | n | , | | C | h | r | i | s | t | o | p | h | e | r | _ | > | ]
12 Angry Men ; Crime | Drama ; Martin Balsam | John Fiedler | Lee J. Cobb ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 0 | 0 | 1 | 4 | 8 | 6 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | L | u | m | e | t | , | | S | i | d | n | e | y | _ | > | ]
Schindler's List ; Biography | Drama | History ; Liam Neeson | Ben Kingsley | Ralph Fiennes ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 0 | 0 | 0 | 2 | 2 | 9 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | S | p | i | e | l | b | e | r | g | , | | S | t | e | v | e | n | _ | > | ]
The Lord of the Rings: The Return of the King ; Action | Adventure | Drama | Fantasy ; Noel Appleby | Ali Astin | Sean Astin ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 0 | 0 | 1 | 3 | 9 | 2 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | J | a | c | k | s | o | n | , | | P | e | t | e | r | _ | > | ]
Pulp Fiction ; Crime | Drama ; Tim Roth | Amanda Plummer | Laura Lovelace ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 0 | 0 | 0 | 2 | 3 | 3 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | T | a | r | a | n | t | i | n | o | , | | Q | u | e | n | t | i | n | _ | > | ]
The Good, the Bad and the Ugly ; Western ; Eli Wallach | Clint Eastwood | Lee Van Cleef ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 0 | 0 | 1 | 4 | 6 | 6 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | L | e | o | n | e | , | | S | e | r | g | i | o | _ | > | ]
Fight Club ; Drama ; Edward Norton | Brad Pitt | Meat Loaf ; [ | < | P | e | r | s | o | n | | i | d | : | 0 | 0 | 0 | 0 | 3 | 9 | 9 | [ | h | t | t | p | ] | | n | a | m | e | : | _ | F | i | n | c | h | e | r | , | | D | a | v | i | d | _ | > | ]
As you can see the columns for Director is returning with multipli characters...
How can I solve this?
Already solve this issue:
import imdb
ia = imdb.IMDb()
top250 = ia.get_top250_movies()
i = 0;
for topmovie in top250:
# First, retrieve the movie object using its ID
movie = ia.get_movie(topmovie.movieID)
cast = movie.get('cast')
directors = movie.get('director')
topActors = 3
i = i+1;
actor_names = [actor['name'] for actor in cast[:topActors]]
director_names = [director['name'] for director in directors[:1]]
if i <= 10:
print(movie, ' ; ', ' | '.join(movie['genres']),
' ; ', ' | '.join(actor_names),
' ; ', ' | '.join(director_names)
);
else:
break;
Thanks!
movie['director'] is a list of Movie objects; casting it to str you will get something like "[<Object1>, <Object2>]" and then you use this string as an iterable for the join method.
You should get the directors' names exactly like you do with the cast names.
For example:
print(movie, ';', ' | '.join(movie['genres']),
';', ' | '.join(actor_names),
';', ' | '.join([d['name'] for d in movie['director']])
);